2009-06-17 67 views
0

我想我知道答案,但是有可能让global.asax Application_Error事件修改原始页面上的文本框,而不是将客户端移动到其他页面?例如: 异常exp = Server.GetLastError()。GetBaseException(); System.Data.SqlClient.SqlException sqlex;global.asax原始页面上的Application_Error报告

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; 
     } 
    } 
    } 
} 

回答

1

如果你想这样做,那么你应该使用页面本身的“OnError”事件。

+0

正确的..问题是,我想完全相同的错误处理整个应用程序。有没有办法使用该代码的所有我的page_OnErrors? – Rob 2009-06-17 19:00:05