【问题标题】:Handling report exceptions using the ASP.NET ReportViewer in Remote and Async mode在远程和异步模式下使用 ASP.NET ReportViewer 处理报告异常
【发布时间】:2009-09-17 23:26:47
【问题描述】:

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

我想添加自定义错误处理逻辑,以便用户收到友好的消息。我怎样才能做到这一点,并且仍然在异步模式下运行查看器,在 SSRS 服务器上呈现报告?

由于页面回发已经完成,因此无法监听 ReportViewer.HandleError 事件。

【问题讨论】:

  • 你遇到了什么异常?
  • 报告 Sproc 中生成的自定义错误,但这应该无关紧要,因为我想处理这些错误,而不是解决它们。

标签: asp.net reporting-services reportviewer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 2022-07-07
    相关资源
    最近更新 更多