Monday 1 December 2008

Javascript not running on PostBack inside an UpdatePanel

I had some Javascript that I wanted to call on every Page_Load. I had an UpdatePanel on my page and I found that the Javascript wouldn't run on a PostBack. My problem was that I needed to user ScriptManager instead of Page.ClientScript. So I switched:

Page.ClientScript.RegisterStartupScript(typeof(Page), "onload", "alert('hello"');", true);

to:

ScriptManager.RegisterStartupScript(this, typeof(Page), "onload", "alert('hello"');", true);

And it worked!

No comments: