代码之家  ›  专栏  ›  技术社区  ›  Robert Wagner

在远程和异步模式下使用ASP.NET ReportViewer处理报表异常

  •  2
  • Robert Wagner  · 技术社区  · 16 年前

    我有一个报表页面,它使用Microsoft.Reporting.WebForms.ReportViewer组件异步呈现报表服务器(SSR)报表。此时,如果发生错误,则在ReportViewer控件中显示一条消息。

    我想添加自定义错误处理逻辑,以便用户得到一条友好的消息。如何实现这一点,并且仍然以异步模式运行查看器,在SSRS服务器上呈现报表?

    侦听ReportViewer.handleError事件将无法工作,因为页回发已完成。

    1 回复  |  直到 16 年前
        1
  •  1
  •   Robert Wagner    16 年前

    在检查了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;
    

    来自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;
    
    推荐文章