Ken Falk - Software Developer

Login
  My Approach     Services     Contact     Experience     Resume     Blog    
 

Injecting Client Script on Asynchronous Postback 5/9/2010

Maybe you know that if you want to inject some client script on the page from server side code you can do something like this:

string strScript = "alert('hello');"; string strKey = "SayHello"; bool bAddTags = true; ClientScript.RegisterStartupScript(this.GetType(), strKey, strScript, bAddTags);

This week, I needed to inject some JavaScript from an asynchronous postback from an UpdatePanel. The above code does not work but after some research I found that the code below does:

string strScript = "alert('hello');"; string strKey = "SayHello"; bool bAddTags = true; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), strKey, strScript, bAddTags);