简体   繁体   English

global.asax Application_Error 在原始页面上报告

[英]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?我想我知道答案,但是否可以让 global.asax Application_Error 事件修改原始页面上的文本框而不将客户端移动到其他页面? something like: Exception exp = Server.GetLastError().GetBaseException();类似于:Exception exp = Server.GetLastError().GetBaseException(); System.Data.SqlClient.SqlException sqlex; 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;
      }
    }
  }
}

If you want to do this then you should use the "OnError" event of the page itself.如果你想这样做,那么你应该使用页面本身的“OnError”事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM