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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to display exceptions/Msg Box

Status
Not open for further replies.

rushdib

Programmer
Jun 12, 2001
203
US
Hi,
I am wondering what is the best way to display exceptions in ASP.net. Do I have to this on a web page or is there a way to display custom exceptions in a message box like on windows forms?

Thanks in advance,

Rushdi
 
What we did for the sql exceptions we wanted to display was have a label on each webform called lblError (or whatever you want to call it).

Then, if a sql exception bubbled its way back up the form, it was caught, and the label's text property was assigned to somethign like this:
&quot;<Script>javascript:alert('&quot; & err.message & '&quot;);</Script>&quot;

This would cause an alert box to appear with the error message on the postback.

Note: we also had to set lblError.Text = &quot;&quot; in the page load so that it would reset after the postback (otherwise the box would keep popping up over and over again).

hth

D'Arcy
 
I would just add one thing:

Setting the label's EnableViewState property = false will keep you from having to set the label's text property back to an empty string on page_load
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Hey, great point Paul! I'll have to let the guys back at my last job know...on second thought, no.
;)

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top