ARTICLE

Alert and Confirmation Message box in ASP.NET using VB.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET April 18, 2011
In this article we will learn how to display Alert and Confirmation Message box in ASP.NET.
 
Reader Level:

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.

a1.gif

Figure1

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

a2.gif

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.

a4.gif

Figure3

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

previously i was working in .net 4.0 page.clientscript.isstartupregister("<script langiage='javascript'>aler('hai');</script>") sorry i am sure about the syntax...but in 3.5 it is not displaying can u give a suggestion

Posted by vivek moorthy Dec 23, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    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.
Become a Sponsor