A ASP.NET web page goes blank if you inject the javascript alert(); function using the Response.Write from the the code behind.

Here is the fix for it.

private void ShowMessage(string message)

{

StringBuilder scriptBuilder = new StringBuilder("<script language=’javascript’>function window.onload(){");

scriptBuilder.Append("alert(‘" + message + "’);");

scriptBuilder.Append("}</script>");

if (!ClientScript.IsClientScriptBlockRegistered("MyMessage"))

{

ClientScript.RegisterClientScriptBlock(this.GetType(), "MyMessage", scriptBuilder.ToString());

}

}

Advertisements