__doPostBack is undefined in IE11

孤街醉人 提交于 2019-11-28 21:31:25

Installing the .NET Framework 4.5 on your web server should resolve it.

http://www.microsoft.com/en-gb/download/details.aspx?id=30653

Alternatively, if you can't install .NET Framework 4.5 there is a Microsoft hotfix for IE11 : http://support.microsoft.com/kb/2836939 (Thank you to @Afract for your comment)

After struggling with the same issue for a few days, we came across this solution:

http://connect.microsoft.com/VisualStudio/feedback/details/806542/fix-internet-explorer-11-not-detected-correctly-by-net-4-0-framework-when-custom-browser-files-are-used.

Add a new .browser file to the App_Browsers folder; we named the file 'IE11.browser', and if the App_Browsers folder doesn't exist, create it.

We then simply copied the body from the link above into the newly created file, redeployed, and now there's no more _doPostBack error.

The body of the file looked like this:

<browsers>
<browser id="IE11" parentID="Mozilla">
  <identification>
    <userAgent match="Trident\/7.0; rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)" />
    <userAgent nonMatch="IEMobile" />
  </identification>
  <capture>
    <userAgent match="Trident/(?'layoutVersion'\d+)" />
  </capture>
  <capabilities>
    <capability name="browser"             value="IE" />
    <capability name="layoutEngine"         value="Trident" />
    <capability name="layoutEngineVersion" value="${layoutVersion}" />
    <capability name="extra"                value="${extra}" />
    <capability name="isColor"             value="true" />
    <capability name="letters"             value="${letters}" />
    <capability name="majorversion"         value="${major}" />
    <capability name="minorversion"         value="${minor}" />
    <capability name="screenBitDepth"     value="8" />
    <capability name="type"                 value="IE${major}" />
    <capability name="version"             value="${version}" />
  </capabilities>
</browser>

<!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11,0) like Gecko -->
<browser id="IE110" parentID="IE11">
  <identification>
    <capability name="majorversion" match="11" />
  </identification>

  <capabilities>
    <capability name="ecmascriptversion"    value="3.0" />
    <capability name="jscriptversion"     value="5.6" />
    <capability name="javascript"         value="true" />
    <capability name="javascriptversion"    value="1.5" />
    <capability name="msdomversion"         value="${majorversion}.${minorversion}" />
    <capability name="w3cdomversion"        value="1.0" />
    <capability name="ExchangeOmaSupported" value="true" />
    <capability name="activexcontrols"     value="true" />
    <capability name="backgroundsounds"     value="true" />
    <capability name="cookies"             value="true" />
    <capability name="frames"             value="true" />
    <capability name="javaapplets"         value="true" />
    <capability name="supportsCallback"     value="true" />
    <capability name="supportsFileUpload" value="true" />
    <capability name="supportsMultilineTextBoxDisplay" value="true" />
    <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
    <capability name="supportsVCard"        value="true" />
    <capability name="supportsXmlHttp"     value="true" />
    <capability name="tables"             value="true" />
    <capability name="supportsAccessKeyAttribute"    value="true" />
    <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter" />
    <capability name="vbscript"             value="true" />
  </capabilities>
</browser>
</browsers>

We didn't have to upgrade our .Net version from 4 to 4.5, and everything is now working as it should.

Hopefully this helps someone having the same frustrating issue!

Put below script in your master page will surely fix it. i had a similar issue and it got fixed.

<script runat="server">

protected override void OnInit(EventArgs e)
{
Page.ClientTarget = "uplevel";
base.OnInit(e);

}
</script> 

Installing Framework 4.5 on our server requires wading through a swamp of red tape and filling out forms, so here is what I did:

Goto site : http://blogs.telerik.com/aspnet-ajax/posts/13-12-19/how-to-get-your-asp.net-application-working-in-ie11

Find the link to download a custom .browser file with the IE11 fix.

Save telerik_ie11_browser_file_fix.zip to your computer and unzip Telerik_IE11_fix.browser

Copy Telerik_IE11_fix.browser to the target server path of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers

Run the following commands on your server (saw it on a hanselman fix blog) cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319 (or whatever framework version your are using)

Run C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regbrowsers –i

Run iisreset on your server

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:

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) { object
    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.

Adding a browser config file to App_Browsers (see above for XML) on Windows 2008 with IIS 7.5 is working for IE 11. On a previous site we did something else, but this is much simpler.

Valer

None of the hotfixes worked for me, neither updating ie.browser file. I'm on a Windows Server 2008 R2.

The only solution that worked though (apart from upgrading to .net 4.5) is the addition of the script suggested by @vishal in this thread.

I discovered a page that was missing the form tag with the runnat='server'. If this is not on your page then the postback will not be able to pass back the controls and properly fire any code behind

What happens is that IE11 is not recognised by Asp.net as a modern browser due to the fact that the user-agent changed, for anyone in same situation the only solution out of 100s of suggestions for me was Adding a setTimeout

instead of using below snipet

__doPostBack('ButtonPostBack', "");   

Use this one

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