In this article we will learn how to display
alert and confirm message Box in ASP.NET.
Alert
Message Box
In ASP.NET to display alert message Box using
Java Script and make a alertmethod().
The below code define the Alert message Box.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication42.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/Javascript" language ="javascript" >
function alert_meth() {
alert("This
show the alert 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"/>
</div>
</form>
</body>
</html>
Now run the application.

Figure1
Now click on
the alert Button to display the alert MessageBox.

Figure2
We can also define the Alert MessageBox with
the Response.Write.
For example
Double click on the Button control and add the
following code.
Protected Sub Button1_Click(ByVal
sender As Object,
ByVal e As EventArgs) Handles
Button1.Click
Response.Write("<script>alert('Hello')</script>")
End Sub
Confirmation Message box
In ASP.NET web page to display the confirm
Message box using java script.
The below code define the Java script to display confirm message Box.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication42.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
language="javascript" type="text/javascript">
function
confirm()
{
if
(confirm ==true)
else
return false;
}
</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="Confirm" Font-Bold="True" ForeColor="Brown" Width="72px"/>
</div>
</form>
</body>
</html>
Now double
click on the button control and add the following code.
Protected Sub Button1_Click(ByVal
sender As Object,
ByVal e As EventArgs) Handles
Button1.Click
Button1.Attributes.Add("onclick",
"return confirm('This is a confirm Box?');")
End Sub
Now run the application and click on the
Confirm Button.

Figure3