Click here to Skip to main content
15,879,535 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.60/5 (4 votes)
14 Oct 2011CPOL 16.4K   3
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)


Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 1 The user will need to pass the hardc... Pin
bbirajdar14-Oct-11 5:42
bbirajdar14-Oct-11 5:42 
GeneralRe: I agree that I forgot to add the alert keyword in the genera... Pin
thatraja14-Oct-11 5:57
professionalthatraja14-Oct-11 5:57 
GeneralRe: Reason for my vote of 1The user will need to pass the hardc... Pin
junaidcodeproject22-Aug-13 20:31
junaidcodeproject22-Aug-13 20:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.