65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Oct 13, 2011

CPOL
viewsIcon

28510

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.

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