65.9K
CodeProject is changing. Read more.
Home

ASP.NET web page goes blank with JavaScript alert()

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.60/5 (4 votes)

Oct 13, 2011

CPOL
viewsIcon

17031

Here is a simpler version. Using the overload method[^](parameter addScriptTags), you can reduce the code.private void ShowMessage(string Message){ if (!ClientScript.IsClientScriptBlockRegistered("MyMessage")) { ClientScript.RegisterClientScriptBlock(this.GetType(), "MyMessage",...

Here is a simpler version. Using the overload method[^](parameter addScriptTags), you can reduce the code.
private void ShowMessage(string Message)
{
  if (!ClientScript.IsClientScriptBlockRegistered("MyMessage"))
  {
    ClientScript.RegisterClientScriptBlock(this.GetType(), "MyMessage", "alert('" + Message + "');", true);
  }
}

public void btnTest_Click(Object sender, EventArgs e)
{
  ShowMessage("Hello World");
}
For AJAX - Updatepanel, use the below one:
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "MyMessage", Message, true);
EDIT The alert keyword moved into general function ShowMessage.

Further Reading