Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a MessageBox 1

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Jun 26, 2002
609
GB
On the application I'm developing I'm building in some error trapping systems. During the testing phase I would like to display the error messages in a messagebox.

I believe you can use the following code...

MessageBox.Show(blah blah)

I'm using this from within a class I've written and I'm not sure of what should come before the MessageBox to allow me to use it. At the moment it is saying that MessageBox is not declared.

Thanks in Advance!

Steve Gordon
 
Server side events run at the Web Server. Telling the Server to display a MessageBox wouldn't work even if allowed as it's the client you want to see the MessageBox on, (within the Web Browser).

You can't display a MessageBox in the way that you want because there's actually no such thing with ASP.net, basically for the above reasons. There is the javascript 'window.confirm' and 'window.alert' but these are client side scripting, not code behind.

I would look at setting up a basic HTML page that you can send the Error details to, and open, from within the catch blocks of your error handling.

Rhys
Buffy: Spike, what are you doing here, five words or less!
Spike: Out for a walk... bitch!
 
Thanks for the quick reply. I'm testing on the server at the moment. So is there a way to display an error message on the server PC or is that equally as impossible?

Steve Gordon
 
Equally impossible I believe. MessageBox is part of Windows Forms and does not exist in ASP.net. There are the client side scripting functions to provide a client side message box, but you'd need to pass them the server side error details, which gets a little complicated for a simple development environment error handler.


Rhys
Buffy: Spike, what are you doing here, five words or less!
Spike: Out for a walk... bitch!
 
Steve,

I always have a lblError located on my page and then any error that I come across I set the .Text equal to the message of the error or the message that I want displayed.

Hope this helps!

Hope everyone is having a great day!

Thanks - Jennifer
 
Message boxes ARE available through ASP.Net. This is how you can have the validation summary appear in a message box:

<asp:ValidationSummary
HeaderText="The following errors were found"
DisplayMode="List"
ShowMessageBox = "True"
runat="server" >

=========================
rollout
=========================
 
Page.RegisterStartupScript()

is a great way to emit client side script to the browser via server side code:

string errorMsg = "Your code blew up. Sorry.";
string script = "<script language=javascript>alert('" + errorMsg + "');</script>";
Page.RegisterStartupScript("error",script);

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top