2009-09-17 207 views
2

我有一個使用Microsoft.Reporting.WebForms.ReportViewer組件異步呈現報表服務器(SSRS)報表的報表頁面。此時如果發生錯誤,則ReportViewer控件內會顯示一條消息。在遠程和異步模式下使用ASP.NET ReportViewer處理報告異常

我想添加自定義錯誤處理邏輯,以便用戶得到一個友好的消息。我如何實現這一點,並仍然以Async模式運行查看器,在SSRS服務器上呈現報表?

由於頁面回發已完成,偵聽ReportViewer.HandleError事件將不起作用。

+0

你做了什麼異常? – 2009-09-18 03:58:36

+0

Sproc報告中生成的自定義錯誤,但是這應該是無關緊要的,因爲我想處理這些錯誤,但沒有解決它們。 – 2009-09-18 05:47:55

回答

1

檢查ReportViewer JavaScript後,我想出了以下解決方案。如果微軟改變這種特殊方法,很容易破壞事情。以下代碼將被添加到頁面的頁眉中,以確保它在ReportViewer JavaScript加載後運行,但在創建RSClientController實例之前運行。

// This replaces a method in the ReportViewer javascript. If Microsoft updates 
// this particular method, it may cause problems, but that is unlikely to 
// happen.The purpose of this is to redirect the user to the error page when 
// an error occurs. The ReportViewer.ReportError event is not (always?) raised 
// for Remote Async reports 
function OnReportFrameLoaded() { 
    this.m_reportLoaded = true; 
    this.ShowWaitFrame(false); 

    if (this.IsAsync) 
    { 
     if(this.m_reportObject == null) 
     { 
      window.location = 
       '<%= HttpRuntime.AppDomainAppVirtualPath %>/Error.aspx'; 
     } 
     else 
     { 
      this.m_reportObject.OnFrameVisible(); 
     } 
    } 
} 
RSClientController.prototype.OnReportFrameLoaded = OnReportFrameLoaded; 

從微軟的ReportViewer腳本文件中的原始代碼(Microsoft.ReportViewer.WebForms,裏面8.0.0.0,.Net框架3.5 SP1)是:

function OnReportFrameLoaded() 
{ 
    this.m_reportLoaded = true; 
    this.ShowWaitFrame(false); 

    if (this.IsAsync && this.m_reportObject != null) 
     this.m_reportObject.OnFrameVisible(); 
} 
RSClientController.prototype.OnReportFrameLoaded = OnReportFrameLoaded; 
+0

好主意。我們可以自己使用它.. – gbn 2009-09-24 19:17:17