You must Sign In to post a response.

How to Display Message Box in ASP.Net Using C#

The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
This thread will be reviewed shortly.
If you think this thread contain inappropriate content, please report to webmaster.
Hi Guys

I have to display Message in Asp.net with c#.pls write a code to me. but i know in vb.net.


Thanks
Krishna


Comments

Author: Pankaj Mishra05 Mar 2006 Member Level: Gold   Points : 2

Hi,
Use javascript alert to display Message box in asp.net
eg
Response.Write("<script>alert('Hello')</script>");

Regards
Pankaj

Author: Rama Krishna K06 Mar 2006 Member Level: Gold   Points : 2

Hi Pankaj

Fst of all Thank you for replying my query.. Is any possibilite in CodeBind in C# .like that in winform.


Thanks
Krishna

Author: Pankaj Mishra06 Mar 2006 Member Level: Gold   Points : 2

Hi,
In ASP.NET we dont have any class like MessageBox in windows forms.We have to use javascript alert the above code is use in code behind only.

Hope this will help u
Pankaj

Author: HimaBindu Vejella03 Apr 2006 Member Level: Gold   Points : 2

u can even use litral control for that

Author: Robert Freunde10 May 2006 Member Level: Bronze   Points : 2

Actually ASP.NET has a class that allows use of the MessageBox.

that class is System.Windows.Forms

if you import that into your webform or whatever, you can use this to display a messagebox:

MessageBox.Show("YourMessageHere",
"YourBoxTitleHere",
MessageBoxButtons.YourChoiceOfButtonsHere,
MessageBoxIcon.YourChoiceOfIconHere);

The last 3 parameters are optional, but recommended.

Hope that helps ya out.

Author: Shashi05 Apr 2007 Member Level: Gold   Points : 2

use javascript in .aspx
<script language="javascript" type="text/javascript">
function confirm()
{
if (confirm ==true)

else

return false;

}
</script>
then write in .aspx.cs
ButtonSave.Attributes.Add("onclick", "return confirm('Are you sure you proceed?');");

Please try with this code?

Author: BSK23 Apr 2007 Member Level: Bronze   Points : 2

I hope these to linls wil solve ur problem

http://www.bassilsoft.com/

http://www.mywebfolder.com/MessageBoxSamples/

Author: Amarendra Satpute05 Aug 2007 Member Level: Bronze   Points : 2

you add namespace system.windows.forms
then you can get messagebox property.

Amarendra Satpute

Author: Amarendra Satpute05 Aug 2007 Member Level: Bronze   Points : 2

you add namespace system.windows.forms
then you can get messagebox property.

Amarendra Satpute

Author: Basawareddy05 Sep 2007 Member Level: Silver   Points : 2

Hi Guys,

There is no class like System.Windows.Form .......

You can use Java Script code as mentioned above.....

Thanks & Regards,
Basawareddy M Gopsen

Author: Ranjan Kr. Dubey12 Sep 2007 Member Level: Bronze   Points : 2

Hi Guys, Please try with javascript as below.

string script = "<script type='text/javascript'>alert('Alert Message');</script>";
Page page = HttpContext.Current.CurrentHandler as Page
If ((!page.ClientScript.IsClientScriptBlockRegistered("alert")) {

page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", script);
}

Author: Shashi20 Sep 2007 Member Level: Gold   Points : 2

in .aspx
private void MessageBox(string msg)
{
Label lbl = new Label();
lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
Page.Controls.Add(lbl);
}

and u can call
MessageBox("try again and enter correct key....");

Author: chakravarthy07 Dec 2007 Member Level: Silver   Points : 2

HI
u can try this one it is working fine
string tmp = "";
tmp = "<script language='javascript'>";
tmp += "alert('Quantity shouldn't exceed the Order Items');";
tmp += "</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);
and if u want to alert message for Exceptions
string tmp = "";
tmp = "<script language='javascript'>";
tmp += "alert('Exception :" + ex.Message + "');";
tmp += "</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);

Author: Brian Street20 Mar 2008 Member Level: Bronze   Points : 2

I've written a MessageBox class and how to on my blog at: http://sceptermt.blogspot.com/2008/02/how-to-create-message-box-class-in-c.html that shows the source code that I used in C# for my web application and details on how it works.

You could also write overloads for the static show() method to allow the class to do a javascript confirm() or a prompt(). I haven't needed that functionality yet so I've just kept it simple.

Author: Mahwish Bute17 Sep 2008 Member Level: Bronze   Points : 5

Hi, I am kind of new to using java script in asp.net
I wanted to know how can we tell if the cancel button is clicked or the ok button was clicked on the following response.
Thanks in advance.


use javascript in .aspx

then write in .aspx.cs
ButtonSave.Attributes.Add("onclick", "return confirm('Are you sure you proceed?');");

Author: Md. Ismail06 Jan 2009 Member Level: Bronze   Points : 3

Its very Simple, create a Method:

private void MessageBox(string message)
{
if (!string.IsNullOrEmpty(message))
{
Response.Write("");
}
}


use it................