IE10 has a nice new little bug which occurs with image buttons on 2nd or consecutive postback on a page which contains an update panel.

You will notice the bug as a broad javascript error message, but behind the scenes the issue occurs due to a bad type conversion to an integer from a floating point which has started to return from the .Net functions.

The official fix is a patch from Microsoft for your server, however, in the meantime you can simply apply the following in your global.asax.

Scott Hanselman has suggested a few things regarding this issue, but I think you will find the solution below to be more straightforward in the short term.

See solution below. (courtesy of R. Prestol)

vb:

'put these in global.asax.cs
Protected Sub Application_PostMapRequestHandler(sender As Object, e As System.EventArgs)
        Dim app As HttpApplication = sender
        Dim handler As IHttpHandler = app.Context.Handler
        Dim page As Page = IIf(TypeOf handler Is Page, handler, Nothing)
        If (page IsNot Nothing) Then
            AddHandler page.Load, AddressOf Page_LoadFix
        End If
    End Sub

    Private Sub Page_LoadFix(sender As Object, e As EventArgs)
        Dim page As Page = HttpContext.Current.Handler
        Dim smg As ScriptManager = ScriptManager.GetCurrent(page)
        If smg IsNot Nothing AndAlso (page.IsPostBack = False OrElse smg.IsInAsyncPostBack = False) Then
            ScriptManager.RegisterOnSubmitStatement(page, page.GetType, "IE10ImgFloatFix", "IE10ImgFloatFix();")
            ScriptManager.RegisterStartupScript(page, page.GetType, "IE10ImgFloatFix_func", "function IE10ImgFloatFix() {try {var o = Sys.WebForms.PageRequestManager._instance;var s = o._additionalInput;s = s.replace(/(.y=\d+)([.]\d+)?/g, '$1');s = s.replace(/(.x=\d+)([.]\d+)?/g, '$1');o._additionalInput = s;} catch (ex){}}", True)
        End If
    End Sub
   

c#:

//put these in global.asax.cs
void Application_PostMapRequestHandler(object sender, EventArgs e)
    {       
        var app = (HttpApplication)sender;
        var handler = (IHttpHandler)app.Context.Handler;
        Page page = handler as Page;
       
        if (page != null)
        {
            page.Load += Page_LoadFix;
        }    
    }

    private void Page_LoadFix(object sender, EventArgs e)
    {
        var page = (Page)HttpContext.Current.Handler;
        var smg = ScriptManager.GetCurrent(page);
        if (smg != null && (page.IsPostBack == false || smg.IsInAsyncPostBack == false))
        {
            ScriptManager.RegisterOnSubmitStatement(page, page.GetType(), "IE10ImgFloatFix", "IE10ImgFloatFix();");
            ScriptManager.RegisterStartupScript(page, page.GetType(), "IE10ImgFloatFix_func", "function IE10ImgFloatFix() {try {var o = Sys.WebForms.PageRequestManager._instance;var s = o._additionalInput;s = s.replace(/(.y=\\d+)([.]\\d+)?/g, '$1');s = s.replace(/(.x=\\d+)([.]\\d+)?/g, '$1');o._additionalInput = s;} catch (ex){}}", true);
        }   
    }
   

References
http://support.microsoft.com/kb/2600088

http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx

http://stackoverflow.com/questions/13784718/asp-net-fails-to-detect-ie10-causing-dopostback-is-undefined-javascript-error

Ronnie Diaz Avatar

Published by

6 responses to “ie10 imagebutton _dopostback undefined bug with update panel script manager”

  1. Peter Harris Avatar
    Peter Harris

    I have implemented this code in my VS2012 4.5 Framework VB.net project and it does not fix the issue in IE10 for me

    1. Ronnie Diaz Avatar

      Can you link 2-3 screenshots illustrating the error? The issue you are experiencing might be slightly different than the one I am referring to in this post but I can help you resolve it.

  2. Alessandro Avatar
    Alessandro

    Great!
    I’m an italian developer and i spent 2 days with this problem. You saved me! Thnaks

  3. naag Avatar
    naag

    other than thias solutions nothing helped…thanks

  4. Hetal Avatar
    Hetal

    Where do i have to place to code into. I know it’s in global.asax but it gives me runtime errors. can you give me correct place, Is it under global.asax.cs file?

    1. Ronnie Diaz Avatar

      Hi Hetal, both functions should be placed into your Global.asax.cs file. Depending on your Visual Studio project type, (website or web application), you may not see Global.asax.cs as this was usually all in one Global.asax file in website projects. In Web Application projects, the Global.asax file that does not have code (the markup file) is generally not modified.

      Also, since the name “Page_Load” is ambiguous with the page load function in pages, I changed the name of the second function in this post to “Page_LoadFix”. Both functions should go in Global.asax(.cs).

      If you receive any other errors or issues please let me know and I would be glad to help you resolve. 🙂

Leave a comment