Function __doPostBack() does not work in iOS, iPadOS browsers - javascript

I'm developing an ASP.NET Webform website using .NET Framework 4.6, C# and Javascript,
I've used HiddenField to store a value from a navigation drawer, then do a postback to update value in UpdatePanel, but seem that the code stucked at __doPostBack() on iOS, iPadOS browsers (all Safari, Chrome, Firefox), for Windows browsers everything works fine. Below is my Javascript code:
function headChange(e) {
__doPostBack('<%=HiddenField1.ClientID%>', '');
};
I tried several methods found on Internet such as:
Added <browserCaps userAgentCacheKeyLength="256"/> in web.config
Added return false; after __doPostBack('<%=HiddenField1.ClientID%>', '');
Replace __doPostBack('<%=HiddenField1.ClientID%>', ''); by <%= Page.ClientScript.GetPostBackEventReference(HiddenField1, String.Empty) %>;
Added a browser file to App_Browsers folder
but all with no luck,
Has anyone encountered the same problem and found the solution for this?
Thank you very much!

I found the error by do Inspect Element in Sarari, the error is shown as follow:
https://ibb.co/ynL1Zhp
"Function.caller used to retrieve strict caller" cause by __doPostBack function in MicrosoftAjaxWebforms.js
Then I found the solution for this by https://stackoverflow.com/a/25686598/7819116
Now my website works well in iOS browsers
Thank you all for the supports!

Related

Browser component (IE) does not show values for document.getElementbyId

I am listening to a server event via a javascript function on my HTML file, which outputs the server answer in the console tab. Since I need to pass this answer to a delphi application, I made the server answer "visible" via a div container. This works fine on Firefox, but on IE the output is not shown. I have then tried to utilize the value of a textarea, which also works on Firefox but not on IE.
I really wonder why it is so hard to get a console output visible on IE?
document.getElementById('my_div_container').innerHTML = JSON.stringify(my_data_I_want_to_see, null, 4);
document.getElementById('my_textarea').value = JSON.stringify(my_data_I_want_to_see, null, 4);
The above lines show a result on Firefox, but on IE there is no output at all. How can I get my data visible on IE?
I found the root cause why IE did not show any console output. I just found out, that the addEventListener() method I was using is not supported in Internet Explorer 8 and earlier versions.
I am very sorry for any confusion.
If you are using TWebBrowser component in Delphi for displaying the webpage do note that by default it running in Internet Explorer 7 compatibility mode.
In order to avoid this you need to opt your program into browser emulation feature
How to have Delphi TWebbrowser component running in IE9 mode?
Don't forget to check MSDN documentation for proper registry value to enable emulation of most modern IE versions.

Exception when I use InvokeScriptAsync in webview

I have WebView in a UWP application that loads webpage, and I have InvokeScriptAsync Method that calls JS function:
InvokeScriptAsync("myFunction", new List<string>());
This code, fires myFunction correctly, and the return is correct.
function myFunction(){
...
return true;
}
But, when I have strange bug... when I set breakpoint in this call, the app blink and latter stops working correctly, but if I remove this breakpoint, the application works fine.
In another side, when I debug JavaScript with Script option in debug settings, the .NET application Works correctly and apparently JavaScript too, but when myFunction return a value, blink again and app stops working.
I'ts posible that debug application influences the behavior of the application? Any idea to find the bug?
Thanks
I can't set breakpoint in C# code and Javascript code at the same time
It is not a supported feature to debug managed codes(C#) and javascript in one Visual Studio Instance. Please see Support Javascript/Managed mixed mode debugging.

HtmlButton not running client side validation in IE11

I having an odd issue with a web form using the HTMLButton in asp.net. For formatting reasons i need to use a <button> construct which is fine, it works in every other browser tested but IE11.
<button id="cmdLogin" runat="server" OnServerClick="cmdLogin_OnServerClick" class="btn btn-more" ValidationGroup="Login" CausesValidation="True">
Login
</button>
When i place a standard asp.net button control, it works, the client side validation is run. The difference i can see between the buttons is the onclick function that ASP.Net injects:
if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate('ModalLogin'); __doPostBack('ctl00$scriptsFooterPlaceholder$TDF971800010$cmdLogin','')
I know that IE11 had some issues with __doPostBack .Net 4 for but i am on .Net 4.51, so i don't think it is that. There are no JavaScript errors that i can see that would stop it (and with the standard button test i guess the client side script is working) and in every other browser i have tested (Chrome, FF, Safari, IE8, IE9, IE10) it is working, just IE11.
Anyone seen this sort of issue?
I thought i would try and hijack the click event in IE11 and see if i could manually force the validation. It turned out to be easier as going through the process the code below, "fixes" the IE11 issue:
<script>
var isIE11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
if (isIE11) {
$('.btn').on('click', function (e) {
e.preventDefault();
});
}
The preventDefault does it, but what is odd is it actually allows the client side validation to work as expected, i.e. it gets caught without forcing a postback (before this the client side stuff was ignored and all forms were validated on postback), so this "fix" is not stopping the client side validation from working.
Note: I do not like or advocate sniffing the browser and version, but in this case as it is only IE11 that has this behavior and i am going to do more research into it after i get this project out the door. It seems like a bug in IE11 with .Net and using the HtmlButton construct which may need a patch from Microsoft.

regex not working in IE

IE version 8
The regex is working fine in firefox:
filename variable contains: testfile.arv (see invalid extension)
if (/\.(doc|xls|ppt|eml|txt|pdf|rtf).?\b/i.test(filename)) {
...
}
in IE it simply passes out as valid name.
EDIT:
After I changed the expression as suggested below. it continued to fail - in IE only. made me realize that it is not about this expression but something about IE and the javascript module I am using to do this.
I am using http://malsup.com/jquery/form/ this form plugin to upload multiple files. this is working properly on firefox, but is not working on internet explorer. it just simply uploads everything and does not show upload progress etc.
since this problem is turning out to be different I will close this thread and submit new question.
Thx for everyone's time and sorry for trouble. I am finding this porting thing a little difficult (from firefox to IE)
try ending it with an "$", like so
if (/\.(doc|xls|ppt|eml|txt|pdf|rtf)$/i.test(filename)) {
// super awesome code
}

webservice.htc, moz-behaviors and Firefox 3

Whilst trying to get our app working in Firefox (I'm a big proponent of X-Browser support but our lead dev is resisting me saying IE is good enough). So I'm doing a little side project to see how much work it is to convert.
I've hit a problem straight away.
The main.aspx page binds to a webservice using the IE only method of adding behaviour through a htc file, which is auto-generated by VS I beleive.
Firefox doesn't support this but there is an xml bindings file which can be used to enable htc support (see here: http://dean.edwards.name/moz-behaviors/overview/). The examples work in FF3 but when I use my webservice.htc as I normally would e.g.:
//Main.aspx
/*SNIP*/
<style type="text/css" media="all">
#webservice
{
behavior:url(webservice.htc);
-moz-binding:url(bindings.xml#webservice.htc);
}
</style>
</head>
<body>
<div id="webservice"></div> <!-- we use this div to load the webservice stuff -->
/*SNIP*/
//Main.js
webservice.useService(url + asmpath + "/WebServiceWrapper.asmx?WSDL","WebServiceWrapper");
I get webservice is not defined (works fine in IE), I obviously tried
var webservice = document.getElementById("webservice")
and
$("#webservice").useService(url + asmpath + "/WebServiceWrapper.asmx?WSDL","WebServiceWrapper");
as well which just gives me "useService is not defined" in Firebug. Which leads me to beleive that the binding is not working. However I can see that webservice.htc is being loaded by Firefox in the Firebug console window.
Anyone got any experience of this?
Am I going to have to rewrite how the webservice is called?
Cheers,
Rob
I don't think that you are on the right way for achieving real cross-browser compatibility. Adding support for IE-specific features for Firefox is definitely not the way to go. What about Opera, Safari, Chrome...? If the app you're working on is used strictly on the intranet then supporting Firefox may be enough however...
IMHO, the code should be refactored, but in an other way. If you are working with ASP.NET 2.0 (in this case you'd need ASP.NET Ajax) or newer, you can create proxy between Ajax and SOAP web services. In that case you would need to rewrite all your behaviors as a JavaScript code which may not be a small feat.
On a side note: AFAIK VS.NET does not generate behaviors.
Sorry if this is not too helpful :(
Your jQuery snippet has an error: since useService is a method defined on the node itself, not the jQuery object, you'd have to do:
$("#webservice")[0].useService(url + asmpath +
"/WebServiceWrapper.asmx?WSDL","WebServiceWrapper");

Categories