Forums » .NET » ASP.NET »

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


Posted Date: 05 Mar 2006      Posted By:: Rama Krishna K Profile photo    Member Level: Gold    Member Rank: 744     Points: 2   Responses: 16



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

Thanks




Responses

#43562    Author: Pankaj Mishra      Member Level: Gold      Member Rank: 52     Date: 05/Mar/2006   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 744     Date: 06/Mar/2006   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 52     Date: 06/Mar/2006   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 42     Date: 03/Apr/2006   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 10/May/2006   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 0     Date: 05/Apr/2007   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 23/Apr/2007   Rating: 2 out of 52 out of 5     Points: 2

I hope these to linls wil solve ur problem

http://www.bassilsoft.com/

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


 
#141958    Author: Amarendra Satpute      Member Level: Bronze      Member Rank: 0     Date: 05/Aug/2007   Rating: 2 out of 52 out of 5     Points: 2

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

Amarendra Satpute


 
#141959    Author: Amarendra Satpute      Member Level: Bronze      Member Rank: 0     Date: 05/Aug/2007   Rating: 2 out of 52 out of 5     Points: 2

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

Amarendra Satpute


 
#148908    Author: Basawareddy      Member Level: Silver      Member Rank: 0     Date: 05/Sep/2007   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 12/Sep/2007   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 0     Date: 20/Sep/2007   Rating: 2 out of 52 out of 5     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      Member Level: Silver      Member Rank: 0     Date: 07/Dec/2007   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 20/Mar/2008   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 17/Sep/2008   Rating: 2 out of 52 out of 5     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      Member Level: Bronze      Member Rank: 0     Date: 06/Jan/2009   Rating: 2 out of 52 out of 5     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................


 
Post Reply

 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.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

Online Members

Shubhangi
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India