Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

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

4.60/5 (4 votes)
14 Oct 2011CPOL 17K  
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.
JavaScript
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:
JavaScript
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "MyMessage", Message, true);


EDIT
The alert keyword moved into general function ShowMessage.

Further Reading


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)