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

#43562    Author: Pankaj Mishra  05 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


Regards,
Pankaj

#43564    Author: Rama Krishna K    06 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


Thanks

#43572    Author: Pankaj Mishra  06 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


Regards,
Pankaj

#46243    Author: HimaBindu Vejella    03 Apr 2006 Member Level: Gold   Points : 2

u can even use litral control for that


http://himabinduvejella.blogspot.com
http://sysntaxhelp.com/asp.net
http://groups.google.com/group/mugh

#52399    Author: Robert Freunde  10 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.

#117375    Author: Shashi    05 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?


Shashi Ray

#120625    Author: BSK  23 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/

#141958    Author: Amarendra Satpute  05 Aug 2007 Member Level: Bronze   Points : 2

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

Amarendra Satpute

#141959    Author: Amarendra Satpute  05 Aug 2007 Member Level: Bronze   Points : 2

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

Amarendra Satpute

#148908    Author: Basawareddy    05 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

#150397    Author: Ranjan Kr. Dubey    12 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);
}

#152630    Author: Shashi    20 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....");


Shashi Ray

#168201    Author: chakravarthy  07 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);

#204714    Author: Brian Street  20 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.

#296631    Author: Mahwish Bute  17 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
<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?');");

#335351    Author: Md. Ismail  06 Jan 2009 Member Level: Bronze   Points : 3

Its very Simple, create a Method:

private void MessageBox(string message)
{
if (!string.IsNullOrEmpty(message))
{
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("alert('" + message + "');");
Response.Write("</script>");
}
}


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


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.