ie10 imagebutton _dopostback undefined bug with update panel script manager

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

About these ads

About Ronnie Diaz

Ronnie Diaz is an enterprise software engineer responsible for front-end and back-end development for companies in many industries. Heavily involved in cloud development, online retail, e-commerce and electronic ordering, fulfillment and customer relational systems.

Posted on February 7, 2013, in Uncategorized and tagged , , , , , , , , , , , . Bookmark the permalink. 6 Comments.

  1. 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

    • 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. Great!
    I’m an italian developer and i spent 2 days with this problem. You saved me! Thnaks

  3. other than thias solutions nothing helped…thanks

  4. 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?

    • 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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: