How to display an error message box in a web application asp.net c#

You can’t reasonably display a message box either on the client’s computer or the server. For the client’s computer, you’ll want to redirect to an error page with an appropriate error message, perhaps including the exception message and stack trace if you want. On the server, you’ll probably want to do some logging, either to the event log or to a log file.

 try
 {
     ....
 }
 catch (Exception ex)
 {
     this.Session["exceptionMessage"] = ex.Message;
     Response.Redirect( "ErrorDisplay.aspx" );
     log.Write( ex.Message  + ex.StackTrace );
 }

Note that the “log” above would have to be implemented by you, perhaps using log4net or some other logging utility.

Leave a Comment