0

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Justin C
  • 1,924
  • 4
  • 28
  • 43
  • I may have made a duplicate: http://stackoverflow.com/questions/338702/how-to-call-a-client-side-javascript-function-after-a-specific-updatepanel-has-be – Justin C Jun 12 '11 at 01:56

2 Answers2

2

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

Brian Dishaw
  • 5,767
  • 34
  • 49
  • thanks for the suggestion but I'm not sure exactly how that would be used. – Justin C Jun 12 '11 at 01:04
  • When I read "when a custom control catches a custom exception and causes a partial" I thought you were saying that an error was thrown during the async postback. Now that I look at it again, I'm guess this isn't the case. :) – Brian Dishaw Jun 12 '11 at 01:09
  • correct. I have one custom control raising an event which the containing page then catches. That event is registered as a trigger for an asynchronous event. At the end of that event I need that one line of javascript to run. – Justin C Jun 12 '11 at 01:13
  • @Justin I've updated my answer. Hopefully this one is more useful than the original. – Brian Dishaw Jun 12 '11 at 01:41
  • 1
    Thank you so much, your post combined with my comment above about this potentially being a duplicate put it all together. FWIW I think you need to use pageLoad instead of PageLoadHandler. Not sure why that would matter but it seemed to. I ended up going with the end handler though. – Justin C Jun 12 '11 at 02:03
1

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 Evil Greebo
  • 7,013
  • 3
  • 28
  • 55