.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

For Beginners: In ASP.NET how to show a Javascript Alert message box?

Posted By:Jean Paul       Posted Date: December 02, 2010    Points: 75    Category: ASP.NET    URL: http://www.dotnetspark.com  

Article showing Javascript Alert message box in ASP.NET

I have seen frequently that beginners in ASP.NET trying to use Windows Forms MessageBox and fails.

I would like to say that MessageBox class is meant for Windows Forms Application and not ASP.NET Web applications.

In ASP.NET applications, you have to:

Use either a page to show the message


Use javascript alert function to show the message (the example is given below)


Create a new web application using File > New Project > Web > ASP.NET Web Application


In the solution Explorer, right click on the Default.aspx and use View Code command.

Replace the Page_Load method code as below:

protected void Page_Load(object sender, EventArgs e)


    string message = "Test Messsage Box in ASP.NET";

    string script = "";

    ClientScript.RegisterStartupScript(GetType(), "key", script);


Now you can execute the application.


On loading the page you will see the following message box (if not enable javascript in your browser)


 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend