Click here to Skip to main content
12,358,242 members (67,424 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.4K views
Posted

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

, 14 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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.
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:
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)

Share

About the Author

thatraja
Web Developer
India India
Retired from Q/A section & Technical forums since 2014

More coming soon....

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 The user will need to pass the hardc... Pin
Balaji Birajdar14-Oct-11 5:42
memberBalaji Birajdar14-Oct-11 5:42 
GeneralRe: I agree that I forgot to add the alert keyword in the genera... Pin
thatraja14-Oct-11 5:57
mvpthatraja14-Oct-11 5:57 
GeneralRe: Reason for my vote of 1The user will need to pass the hardc... Pin
junaidcodeproject22-Aug-13 20:31
memberjunaidcodeproject22-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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 14 Oct 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid