Thursday, July 23, 2009

Register client script when using Update panel

Page.RegisterClientScriptBlock(string key,string script) will not work if control is inside the update panel. To solve this problem we need to use
ScriptManager.RegisterClientScriptBlock(Control,Type,string key,string script,bool addScriptTags);
Let us take an example suppose a Datalist named "dtalistNames" is in updatepanel and we need to register the script in Datalist's item command event. Then use following text to alert a message.
C# syntax.
string Message="";
Message="";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "mess", Message, false);