Search code examples
c#javascriptasp.netelasticlayout

executing one line of javascript on asynchronous ajax event in ASP.NET


I am using the Elastic CSS framework on an ASP.NET site. It is doing a great job of sizing the various containers I have until an UpdatePanel executes a partial postback. The solution as I understand it is to execute the following line of javascript

Elastic.refresh();

I'm pretty good with C# and ASP.NET but not so much with javascript. As I understand it, RegisterStartupScript only registers the script, I still need a control to then execute it.

So how can I get this one line of javascript to execute when a custom control catches a custom exception and causes a partial postback?


Solution

  • Edit

    In javascript on your page you could also try something like this

    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);
    function PageLoadHandler()
    {
        Elastic.refresh();
    }
    

    This handler will run after any callback but sender._postBackSettings.panelID will allow you to filter it to the panel you want.

    Alternativly you could try if end request fits your needs better.

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function PageLoadHandler()
    {
        Elastic.refresh();
    }
    

    Original

    Do you have a ScriptManager control on the page that has the UpdatePanel? If so you might be able to leverage the ScriptManager.AsyncPostBackError and have it execute your method.

    http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.asyncpostbackerror.aspx