Running a javascript function after UpdatePanel.Update()

Found this forum post to be very helpful and I think I may employ this more often when doing UpdatePanel related messaging-when-done…

Run a javascript function after UpdatePanel.Update() – ASP.NET Forums:

You should call the method in this way:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), “MyScriptName”, “<script type=’text/javascript’>functionToCall(‘hello world’);</script>”, false);

The problem could be the fact that you are using this instead of this.Page. Also instead language=’javascript’ you can use type=’text/javascript’.

All I know is that when I launched the script properly passing this.Page it worked properly. I had derived from Page to a custom base page, so maybe that had something to do with it.

Additionally, I refined it just a bit by building the script dynamically in a string and then passing that instead of just a literal in the static method call.

One more improvement I was considering is to embed this as a method on my aforementioned customized base page. Then i can just pass a name and the script to the method, and I won’t have to worry about the messy details every time.

Leave a comment

Your email address will not be published. Required fields are marked *