Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How We can Display MessageBox in ASP.net.

Author: DevASP
Download Source Code : 604_ShowMsgBox.zip

This article is about how you can display a message box in ASP.NET. Its very easy to show a message box in your desktop application but when you want to show a message box in your web application you

Steps you will do.

 

Start visual studio and create a new web application. Open the HTML design of your web page and add the following HTML code to design thee layout of your web page.

 

 

<HTML>

<HEAD>

<title>WebForm1</title>

<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>

<body MS_POSITIONING="GridLayout" bgColor="#009999">

<form id="Form1" method="post" runat="server">

<center>

<asp:Label id="Label2" runat="server" ForeColor="White">A simple example that how you can show a message box in asp.net</asp:Label>

<br>

<br>

<asp:Label id="Label1" runat="server" ForeColor="White">Click button to show the message box</asp:Label>

<br>

<br>

<asp:Button id="btn_show" runat="server" Text="Show"></asp:Button>

<br>

<br>

<asp:Label id="Label3" runat="server" ForeColor="White">Dont forget to visit www.devasp.com</asp:Label>

<br>

<br>

<h3><a href="http://www.devasp.com">Devasp Team</a></h3>

</center>

</form>

</body>

</HTML> 

 

 

Now open the code window of your web form and add the following function which will accept a parameter to show the message box. The function is as below.

 

 

Public Sub UserMsgBox(ByVal sMsg As String)

        Dim sb As New StringBuilder

        Dim oFormObject As System.Web.UI.Control

        sMsg = sMsg.Replace("'", "\'")

        sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))

        sMsg = sMsg.Replace(vbCrLf, "\n")

        sMsg = "<script language=javascript>alert(""" & sMsg & """)</script>"

        sb = New StringBuilder

        sb.Append(sMsg)

        For Each oFormObject In Me.Controls

            If TypeOf oFormObject Is HtmlForm Then

                Exit For

            End If

        Next

        oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))

    End Sub 

 

  

Now in the click event of the button call the above function and pass a string as parameter which you want to show in message box.

 

 

UserMsgBox("Welcome to www.devasp.com  .....!")

 

Run your application and click the button to show the message box.

Article Comments
may i know how to retrive images from sqldatabase and how to bind images from database using picturebox in vb.net

Posted on 10/14/2006 11:08:43 AM by M.Ramu

plz send me messagebox show in asp net

Posted on 11/11/2006 10:06:38 AM by rama chandra sahoo

when iam trying to display messagebox in visualstudio.net 2005 it's shows the error like this system.web.ui.Literalcontrol doesn't create child controls plz help me out

Posted on 12/5/2006 8:29:56 AM by saritha

How can i use it with C# platform?

Posted on 12/15/2006 5:39:40 AM by santhosh

How can i do this in C#?

Posted on 1/11/2007 1:33:25 AM by keerti

how can i display a message in c# web application.

Posted on 1/17/2007 1:06:40 AM by shivanand

plz send the code how to refresh the record from asp.net page

Posted on 1/17/2007 7:15:26 AM by venu

How to display messagebox in asp.net using c#? I want same sample in above question.

Posted on 1/19/2007 4:56:04 AM by vasugi

its very good but can u tell me how can call two sub on click of a single button.

Posted on 1/23/2007 12:35:29 AM by Manoj Singh

Well Umar you are making wrong concepts please try to review your code again. In your code you are displaying message box after page's postback but if you know how to attach javascript function to your ASP.NET button control then you can do the same thing very easily and you can show the message box without page's postback. See source code below:

VB.NET Version:
===============================
<Script Language="VB" Runat="Server">

Private Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
BtnMessage.Attributes.Add("onclick", "return showMessage(""Hello From ASP.NET Message Box"");")
End Sub

</Script>


<html>
<head>
<title>Message Box in ASP.NET</title>
<script type="text/javascript" language="javascript">

function showMessage(msg)
{
alert(msg);
return false;
}

</script>
</head>
<body>
<form runat="server">
<asp:Button id="BtnMessage" Text="Show Message Box" runat="server" />
</form>
</body>
</html>
===============================


C# Version:
===============================
<Script Language="C#" Runat="Server">

private void page_load(object sender, EventArgs e)
{
BtnMessage.Attributes.Add("onclick", "return showMessage(\"Hello From ASP.NET Message Box\");");
}

</Script>


<html>
<head>
<title>Message Box in ASP.NET</title>
<script type="text/javascript" language="javascript">

function showMessage(msg)
{
alert(msg);
return false;
}

</script>
</head>
<body>
<form runat="server">
<asp:Button id="BtnMessage" Text="Show Message Box" runat="server" />
</form>
</body>
</html>
===============================

Best Regards,
Zeeshan

Posted on 2/10/2007 2:54:46 PM by Zeeshan Mehmood

Thank u.
realy that code give me a new turn
to developthis .
regard
Javed Akhtar

Posted on 3/2/2007 2:37:41 AM by Javed Akhtar

How can we display message box in webpage(asp.net) using vb.net

Posted on 3/4/2007 8:59:44 AM by Manju

This article is very good.it really helped me.I was also trying the same thing ie how to diplay msgbox in asp.net through C#.

Code is simple also.
Really very helpful.Thanks a lot.

Posted on 3/14/2007 7:49:54 AM by Rashmi Agarwal

I am interested in asp.net.I was did some project in ASP.Net.Will you give me some extra knowledge about ASP.Net

Posted on 4/12/2007 7:19:30 AM by chetan

thanks thats really work for me.
i need help again plz..
may i know how to retrive images from sqldatabase and how to bind images from database using images in c#.net

Posted on 4/21/2007 10:32:47 AM by kirti potfode

thanks Zeeshan Mehmood for the code on messagebox in asp.net. it gave me a new turn.

Posted on 4/27/2007 6:15:31 AM by moradeke

[url=http://asian-comforter-set.comforterabout.com/aqua-brown-comforter.php][b]100 comforter down goose[/b][/url] laura ashley down comforter, aqua brown comforter, asian style comforter, 100 comforter down goose, california king comforter bed in a bag, baby comforter set, bed in a bag comforter set, bag bed bedding comforter in [url=http://baby-comforter-ny-yankee.comforterabout.com/][i]baby comforter set[/i][/url] baby comforter, baby comforter ny yankee, baby comforter silk, baby crib comforter set, baby crib comforter set, baby comforter [url=http://baby-comforter-ny-yankee.comforterabout.com/baby-comforter.php][b]queen bed in a bag comforter set[/b][/url] asian style comforter, asian king comforter, queen bed in a bag comforter set, bunk bed comforter, california king comforter bed in a bag, bag bed cheap comforter in set, comforter bed in a bag [url=http://california-king-bed-spread-and-comforter.comforterabout.com/bag-bed-cheap-comforter-in-set.php][u]bag bed cheap comforter in set[/u][/url] king bed comforter, bed in a bag comforter set, twin bed comforter [url=http://king-bed-comforter.comforterabout.com/king-bed-comforter.php][i]king bed comforter[/i][/url] bed bedding bedroom comforter full furnishing skirt, full bed comforter [url=http://king-bed-comforter.comforterabout.com/discount-bed-comforter.php][i]discount comforter and bed spread[/i][/url] designer bed comforter, discount bed comforter, discount comforter and bed spread [url=http://bed-comforter-linen.comforterabout.com/bath-bed-bed-comforter-fashion-linen-linen-luxury-mattress-pad-robe-set-towel.php][u]amance bed comforter furnishing linen pillow[/u][/url] luxury comforter bed set, bath bed bed comforter fashion linen linen luxury mattress pad robe set towel, amance bed comforter furnishing linen pillow, bed california comforter king set [url=http://water-bed-sheet-comforter-set.comforterabout.com/bed-comforter-sheet-twister.php][b]toddler bed comforter set[/b][/url] bag bed comforter in set, to

Posted on 6/18/2007 8:18:03 AM by replcacetospmcomments

asian style comforter, laura ashley down comforter http://asian-comforter-set.comforterabout.com/aqua-brown-comforter.php aqua brown comforter, 100 comforter down goose http://baby-comforter-ny-yankee.comforterabout.com/ baby comforter set, baby comforter silk, bag bed bedding comforter in, california king comforter bed in a bag, baby crib comforter set, baby crib comforter set, baby comforter ny yankee, bed in a bag comforter set, baby comforter, baby comforter, queen bed in a bag comforter set, asian style comforter http://baby-comforter-ny-yankee.comforterabout.com/baby-comforter.php asian king comforter, california king comforter bed in a bag, comforter bed in a bag, bunk bed comforter, bag bed cheap comforter in set http://california-king-bed-spread-and-comforter.comforterabout.com/bag-bed-cheap-comforter-in-set.php twin bed comforter http://king-bed-comforter.comforterabout.com/king-bed-comforter.php bed bedding bedroom comforter full furnishing skirt, bed in a bag comforter set, king bed comforter, discount comforter and bed spread, discount bed comforter http://king-bed-comforter.comforterabout.com/discount-bed-comforter.php full bed comforter, designer bed comforter, bath bed bed comforter fashion linen linen luxury mattress pad robe set towel, luxury comforter bed set, amance bed comforter furnishing linen pillow http://bed-comforter-linen.comforterabout.com/bath-bed-bed-comforter-fashion-linen-linen-luxury-mattress-pad-robe-set-towel.php bed california comforter king set, toddler bed comforter set http://water-bed-sheet-comforter-set.comforterabout.com/bed-comforter-sheet-twister.php bed comforter sheet twister, bag bed comforter in set, water bed sheet and comforter, bed black comforter red, bed comforter set toddler, bed comforter set silk, bed comforter day set http://water-bed-sheet-comforter-set.comforterabout.com/bed-comforter-set-silk.php bed comforter spread tropical, bed bedding comforter spread http://twin-bed-comforter.comforterabout.com/bed-be

Posted on 6/18/2007 8:18:10 AM by replcacetospmcomments

asian style comforter, laura ashley down comforter http://asian-comforter-set.comforterabout.com/aqua-brown-comforter.php aqua brown comforter, 100 comforter down goose http://baby-comforter-ny-yankee.comforterabout.com/ baby comforter set, baby comforter silk, bag bed bedding comforter in, california king comforter bed in a bag, baby crib comforter set, baby crib comforter set, baby comforter ny yankee, bed in a bag comforter set, baby comforter, baby comforter, queen bed in a bag comforter set, asian style comforter http://baby-comforter-ny-yankee.comforterabout.com/baby-comforter.php asian king comforter, california king comforter bed in a bag, comforter bed in a bag, bunk bed comforter, bag bed cheap comforter in set http://california-king-bed-spread-and-comforter.comforterabout.com/bag-bed-cheap-comforter-in-set.php twin bed comforter http://king-bed-comforter.comforterabout.com/king-bed-comforter.php bed bedding bedroom comforter full furnishing skirt, bed in a bag comforter set, king bed comforter, discount comforter and bed spread, discount bed comforter http://king-bed-comforter.comforterabout.com/discount-bed-comforter.php full bed comforter, designer bed comforter, bath bed bed comforter fashion linen linen luxury mattress pad robe set towel, luxury comforter bed set, amance bed comforter furnishing linen pillow http://bed-comforter-linen.comforterabout.com/bath-bed-bed-comforter-fashion-linen-linen-luxury-mattress-pad-robe-set-towel.php bed california comforter king set, toddler bed comforter set http://water-bed-sheet-comforter-set.comforterabout.com/bed-comforter-sheet-twister.php bed comforter sheet twister, bag bed comforter in set, water bed sheet and comforter, bed black comforter red, bed comforter set toddler, bed comforter set silk, bed comforter day set http://water-bed-sheet-comforter-set.comforterabout.com/bed-comforter-set-silk.php bed comforter spread tropical, bed bedding comforter spread http://twin-bed-comforter.comforterabout.com/bed-be

Posted on 6/18/2007 8:18:27 AM by replcacetospmcomments

Very Helpful
Thanks a lot

Posted on 6/26/2007 2:40:56 AM by Adel

oh really its great!!!!

it is working very fine.....

tx
nishu

Posted on 7/21/2007 7:55:36 AM by nirpendra

How to pass the Dynamic Message to java script. I.e. on click of the button i want to do some calculations and based on the calculations i want to pass the different Message to the Confirmation box.

Posted on 8/27/2007 6:08:26 AM by Prashanth Reddy

This Artical is really good,I faced this MSGbox problem in Interview
Thanks

Posted on 8/29/2007 1:18:34 PM by Balaji.b

hi
the code is simple.i have a doubt.if i want to pass the value from asp.net to java script in between the message .

for ex "hello from sujatha ".how is it to be done.post the reply ASAP

Posted on 9/27/2007 8:51:52 AM by sujatha

Hi,i m doing project in asp.net can any one tell how to add textbox,radiobutton, labels.... in msgbox i want code for that it should in vb.net

Posted on 10/6/2007 1:20:26 AM by deepa

thanks alot.

its really very gud & very simple code on message box in asp.net(C#).

Posted on 10/24/2007 5:01:30 AM by Charu

how can we use msgbox in asp.net

Posted on 1/11/2008 2:22:33 AM by kalpana tamrakar

how to disable child node when clicking another node using asp.net, how to show buttons in message box, how to add serial numbers in grid using asp.net

Posted on 1/13/2008 8:51:54 AM by gtanand

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How we can Create Cascading Menu in web application.

Disclaimer - Privacy
© 2002-2017 DevASP.net