Javascript Alert message from code behind in ASP.NET

We all know that we can display javascript alert message from code behind in ASP.NET using Page.ClientScript.RegisterStartupScript.
Page.ClientScript.RegisterStartupScript(this.GetType(),"myscript","alert('hello world!');");
However, above method can break under ASP.NET AJAX environment. For AJAX we need to use ScriptManager.RegisterStartupScript. Below code displays javascript alert message both in AJAX environment and on regular page as well.
ScriptManager.RegisterStartupScript(this,this.GetType(),"myscript","alert('hello world!');",true);
For more information on ClientScriptManager.RegisterStartupScript Method you can visit,

No comments:

Post a Comment