リモートモードおよび非同期モードでASP.NET ReportViewerを使用してレポート例外を処理する

StackOverflow https://stackoverflow.com/questions/1441852

質問

Microsoft.Reporting.WebForms.ReportViewerコンポーネントを使用してレポートサーバー(SSRS)レポートを非同期に表示するレポートページがあります。現在、エラーが発生した場合、ReportViewerコントロール内にメッセージが表示されます。

カスタムエラー処理ロジックを追加して、ユーザーにわかりやすいメッセージが表示されるようにします。 SSRSサーバーでレポートをレンダリングしながら、非同期モードでビューアーを実行しながらこれを実現するにはどうすればよいですか?

ページのポストバックが既に完了しているため、ReportViewer.HandleErrorイベントをリッスンしても機能しません。

役に立ちましたか?

解決

ReportViewer JavaScriptを調べた後、次のソリューションを思いつきました。 Microsoftがこの特定の方法を変更すると、問題が発生しやすくなります。次のコードをページのヘッダーに追加して、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;

Microsoft ReportViewerスクリプトファイル(Microsoft.ReportViewer.WebForms、8.0.0.0、.Net Framework 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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top