Rob
Rob

Reputation: 2110

global.asax Application_Error reporting on original page

I think I know the answer, but is it possible to have the global.asax Application_Error event modify a textbox on the original page and not move the client to a different page? something like: Exception exp = Server.GetLastError().GetBaseException(); System.Data.SqlClient.SqlException sqlex;

if (exp is System.Data.SqlClient.SqlException) {
  sqlex = (System.Data.SqlClient.SqlException) exp;
  if (sqlex.Number == 50000) {
    if (HttpContext.Current.CurrentHandler is Page) {
      Page p = (Page) HttpContext.Current.CurrentHandler;
      Control c = p.FindControl("ErrorText");
      if (c != null && c is Label) {
        ((Label) c).Text = exp.Message;
        Server.ClearError();
        return;
      }
    }
  }
}

Upvotes: 0

Views: 870

Answers (1)

David
David

Reputation: 34543

If you want to do this then you should use the "OnError" event of the page itself.

Upvotes: 1

Related Questions