Click here to Skip to main content
Click here to Skip to main content

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

By , 14 Oct 2011
 
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)

About the Author

thatraja
Web Developer
India India
Member
Programmer | CodeProject MVP, Mentor | Author | Geek | Blogger | Bachelor | Dude
 
About him & his blog? check out here.
 
In Codeproject, he posted a blogpost & more than couple of Tip/Tricks, hope he'll write more soon. And he got a place in CCC table.
 
In programming, he wants to go with new things like HTML5, CSS3, WP7, Silverlight, WPF, WCF, etc.,
 
His hobbies are watching movies, Codeproject, being alone, etc.,

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralReason for my vote of 1 The user will need to pass the hardc... PinmemberBalaji Birajdar14 Oct '11 - 5:42 
Reason for my vote of 1
The user will need to pass the hardcoded javascript 'alert' keyword everytime this function is called. Overall , the alternative is not generic in nature.
 
The major mistake in this code is , it does not defines the <script>...</script> tags for javascript.
 
If you make this change, then it will be the same as the code above and will not be an 'alternative' as we say
GeneralRe: I agree that I forgot to add the alert keyword in the genera... Pinmvpthatraja14 Oct '11 - 5:57 

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 14 Oct 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid