Skip to content Skip to sidebar Skip to footer

Async Postback Not Working

I'm using this gauge in my contentplaceholder. http://www.dariancabot.com/projects/jgauge_wip/ MyControl.ascx:

Solution 1:

I was able to solve this with by going:

$(document).ready(function () { 
    Sys.WebForms.PageRequestManager.getInstance()
        .add_endRequest(<%=this.ClientID%>_ctlEndRequestHandler); 
    var <%=this.ClientID%>_ctl; 

    <%=this.ClientID%>_ctl = new jGauge();  
    <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl'; 
    <%=this.ClientID%>_ctl.init();
});

function <%=this.ClientID%>_ctlEndRequestHandler(sender, args){
    var <%=this.ClientID%>_ctl; 
    <%=this.ClientID%>_ctl = new jGauge();  
    <%=this.ClientID%>_ctl.id = '<%=this.ClientID%>_ctl'; 
    <%=this.ClientID%>_ctl.init(); 
}

The only real difference is that the postback checks are no longer taking place. Your underlying problem is that $(document).ready will not fire on partial postbacks, which means that isPostBack is never actually getting set to true. Because of this, Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); was never executing, meaning that your EndRequestHandler never ran.

Edit

The other issue is that naming the method EndRequestHandler is guaranteed to cause problems if you have more than one of the control at the same time. To get around this, I appended <%=this.ClientID%>_ctl to the name of EndRequestHandler to ensure it was unique.

More info:

How do I use a jQuery $(document).ready and an ASP.NET UpdatePanel together?

http://encosia.com/document-ready-and-pageload-are-not-the-same/

Post a Comment for "Async Postback Not Working"