简体   繁体   中英

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?

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

This is a guess, but I'd try using a literal control w/in the ajax panel that contained the following:

<script language="javascript">
Elastic.refresh();
</script>

If I'm right the Ajax panel will reload and that will automatically execute that line of code when it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM