Blog Archives

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)


'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


//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);



Using jQuery and ScriptManager to update dynamic page elements

I recently came across a situation where an element on the page was not updating dynamically after post backs.

It was quick and easy to add an update panel and the necessary logic to use the built in asp .Net ajax callbacks.

I simply added an update panel around the code that needed to be updated, and an invisible button within the update panel to trigger the postback. I then called this button using javascript click() event of the button.

However, this caused some conflicts with some other pre-existing ajax code and modal dialogs, so I turned to another solution.

Rather than re-work these controls and methods which were already functioning correctly and extensively implemented, I added a small snippet of code on page load for the content pages which I wanted to trigger a force reload. This did the trick.


ScriptManager.RegisterStartupScript(Me, Me.GetType(), "loadminicart", "$('#minicart').load('" & _
strRootSiteURL & "minicartdata.aspx');", False)


ScriptManager.RegisterStartupScript(this, this.GetType(), "loadminicart", "$('#minicart').load('" + strRootSiteURL + "minicartdata.aspx');", false);

“minicartdata.aspx” is a dynamic page with no masterpage, header, footer or body HTML tags specified – only div’s and content elements.

“minicart” is the id of the div which minicartdata.aspx will be loaded into.

In my specific instance, there were only two pages which I needed to force the minicart content to reload. As a requirement, I needed the reload to occur after an operation on these pages, so since there were only two pages, it was easy to specify this code in both.

In some cases, you may want to be able to easily trigger a refresh from code behind without having to place the above code in every page. For this I recommend simply creating a global function and placing the snippet above, then calling the global function from anywhere needed.

Another, more object oriented approach is to create your own type which inherits page, and use this as the base type for all your content pages. You could then place a function in your new type which contains the snippet above. This effectively has the same end result as using a global function.

Hope this information can be as useful to someone else as I found it to be. 😉