IE10 SCRIPT5009: '__doPostBack' is undefined

我的未来我决定 提交于 2020-01-09 04:18:32

问题


I am facing a problem on IE10 with ASP.NET controls that requires JavaScript post back[like, link button].

It is properly working on the IE9 version as well as on IE10 Compatibility mode. But on the IE10 standard mode, it is giving below error. SCRIPT5009: '__doPostBack' is undefined

[I have created a demo project with a simple asp:link button that redirects to another page.]

Tried the solution, but didn't work for me

Can anyone suggest fix for this?


回答1:


There is apparently a bug in the browser definition files that shipped with .NET 2.0 and .NET 4. The definition files do not cater for IE10 as a browser version and hence defaults to a default definition which doesn't support JavaScript.

Scott Hanselman has a very detailed writeup about this issue here: http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx

Scott proposes two solutions, with the first one being the recommended one:

1. Machine-wide fix Download and install a hotfix on the server:

  • .Net 4 (http://support.microsoft.com/kb/2600088)
  • .Net 2 (http://support.microsoft.com/kb/2600100, http://support.microsoft.com/kb/2608565)

2. Site-only fix Install the App_BrowsersUpdate package from NuGet into your website to import new ie and firefox browser definitions.

  • .Net 4 (http://nuget.org/List/Packages/App_BrowsersUpdate)
  • .Net 2 (http://nuget.org/List/Packages/App_BrowsersUpdate.net20)



回答2:


If you have tried the fix and you are still seeing the error in IE11, updating the .net framework to 4.5 would work.




回答3:


IE 10 has issues :

It can not recognize the links with _doPostBack [Which are basically seen in the HTML output of ASP Link Button]

You can refer following link for the fix :

http://ronniediaz.com/2013/02/07/ie10-imagebutton-_dopostback-undefined-bug-with-update-panel-script-manager/




回答4:


Essentially what's going on is that there are 2 missing html hidden elements "eventtarget" and "eventargument", as well as a missing function "__doPostBack".

These are missing from the DOM.

I tried all the fixes listed for this and none worked. However using a combination of jquery and javascript there is an unobtrusive solution. Add this to your javascript on document ready and you're off to the races (This is a much quicker alternative than installing the .net framework 4.5 on your server, although if you can install 4.5 thats the way to go):

if ($('#__EVENTTARGET').length <= 0 && $('#__EVENTARGUMENT').length <= 0) {
  $('#YOUR_ASPNET_FORMID').prepend('<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />');
}

if (typeof __doPostBack == 'undefined') {
  __doPostBack = function (eventTarget, eventArgument) { 
    var theForm = document.forms['YOUR_ASPNET_FORMID'];
    if (!theForm) {
      theForm = document.YOUR_ASPNET_FORMID;
    }
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
      theForm.__EVENTTARGET.value = eventTarget;
      theForm.__EVENTARGUMENT.value = eventArgument;
      theForm.submit();
    }
  };
}

I understand that some of said installing 4.5 fixes this. I would definitely recommend that. However, if you're like me working on an enterprise public facing site with a cms system baked in .net 4, this might just be an easier solution, as opposed to possibly introducing new bugs created from updating your platform.



来源:https://stackoverflow.com/questions/15273618/ie10-script5009-dopostback-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!