SIGN UP MEMBER LOGIN:    
ARTICLE

How to show Alert and Confirmation Message box in ASP.NET

Posted by Syed Shakeer Articles | ASP.NET Programming February 21, 2011
In this article beginners can learn how to display a Message Box in Asp.net using JavaScript.
Reader Level:


In this article beginners can learn how to display a Message Box in Asp.Net using JavaScript.

1. Alert Message Box:

This type of Message Box is used to give alert information to the user. This can be done using the "alert" method. Use the alert method in <script> </script> tags by using a function with a method name. Call this function on client click event in a Button as follows in the following code.

e.g.: alert("write Message here")

Image of Alert Message Box:

Confirm.gif

 

<head runat="server">
<title>Untitled Page</title>
<script type="text/Javascript" language ="javascript" >
function alert_meth()
{
alert("Client Side MessageBox");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Style="z-index: 100; left: 64px; position: absolute;
top: 88px" Text="Alert" OnClientClick ="alert_meth()" Font-Bold="True" ForeColor="Red" Width="72px"/>

2. Confirmation Message Box:

This type of Message Box is used to give a warning to the user. Suppose user is deleting records; at that time this type of message box is used to give confirmation about the action to be taken or not by showing two Buttons as "YES'" and "NO". If the user clicks on the "YES" Button it returns Boolean "True" and for "NO" button it returns Boolean "False".


Image of Confirm Message Box:

Confirm1.gif

<head runat="server">
<title>Untitled Page</title>
<script type="text/Javascript" language ="javascript" >
function confirm_meth()
{
  if( confirm("Do you want to continue!Click 'YES'")==true)
  {
        document.writeln ("<b>You had click on 'YES' Button</b>");
   }
  else
  {
       document.writeln ("<b>You had clic on 'NO' Button</b>");
  }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnconfirm" runat="server" Font-Bold="True" ForeColor="Red" Style="z-index: 101;
left: 272px; position: absolute; top: 208px" Text="Confrimation MsgBox"
OnClientClick =" return confirm_meth()" Width="160px" />

Thanks for Reading my Article!
Syed Shakeer Hussain

Login to add your contents and source code to this article
share this article :
post comment
 

it is good

Posted by Son Nguyen Duc May 09, 2011

yes.. you are right...

Posted by Suthish Nair Feb 22, 2011

Sounds good. But i will still suggest as this is repeated by so many folks, nothing serious but its about channeling the efforts in the right direction to ensure the organization of this website and if some one disgree on having the contents organized on this website then i respect their opinion.

Posted by knights Feb 21, 2011

Dont want to talk about it, Admins needs to take care of this. The person who approved the article even not corrected the spelling mistakes.

Posted by Suthish Nair Feb 21, 2011

Dont want to talk about it, Admins needs to take care of this. The person who approved the article even not corrected the spelling mistakes.

Posted by Suthish Nair Feb 21, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor