2009-06-17 69 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