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()

5.00/5 (1 vote)
17 Oct 2011CPOL 28.5K  
How to fix the issues when an ASP.NET web page goes blank with JavaScript alert() .

An ASP.NET web page goes blank if you inject the JavaScript alert(); function using Response.Write from the code-behind. Here is a fix for it.


C#
private void ShowMessage(string message)
	{
		String scriptMessage = "<script language='javascript'>function window.onload(){alert('" + message + "');}</script>";
		if (!ClientScript.IsClientScriptBlockRegistered("MyMessage"))
		{
			ClientScript.RegisterClientScriptBlock(this.GetType(),"MyMessage", scriptMessage.ToString());
		}
	}

License

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