How To Inject Javascript during partial postback in ASP.Net
Posted by senthilsweb on December 15, 2007
Injecting Javascript Codes using ClientScriptManager class i.e. RegisterClientScriptBlock in asp.net codebehind will not work for partial postback [ASP.NET AJAX Calls].
To make it work we need to use ScriptManager class’s ScriptManager.RegisterStartupScript, ScriptManager.RegisterClientScriptBlock methods
Example:
string msg = string.Format(“alert(‘Test Javascript from partial postback’);”);
ScriptManager.RegisterStartupScript(TestButton, typeof(Button),”Test_my_script”,msg, true);
TestButton => The control which triggered the partial postback [It may be other controls which are inside the updatepanel]
typeof(Button) => System.Type object for a type
Test_my_script => any unique string as key
msg => Javascript code to be injected
true /false => Adds javascript script tags i.e. <script></script>




NaReN said
Instead of typeof(Button), this.GetType() can be used; and so need to remember that which control triggered the partial postback.
Yuriy said
If partial postback is caused by Infragistics controls, you need a slightly different approach: http://codecorner.galanter.net/2009/07/28/injecting-client-script-into-infragistics-async-postback/