在远程和异步模式下使用ASP.NET ReportViewer处理报告异常
问题描述:
我有一个使用Microsoft.Reporting.WebForms.ReportViewer组件异步呈现报表服务器(SSRS)报表的报表页面。此时如果发生错误,则ReportViewer控件内会显示一条消息。在远程和异步模式下使用ASP.NET ReportViewer处理报告异常
我想添加自定义错误处理逻辑,以便用户得到一个友好的消息。我如何实现这一点,并仍然以Async模式运行查看器,在SSRS服务器上呈现报表?
由于页面回发已完成,侦听ReportViewer.HandleError事件将不起作用。
答
检查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
你做了什么异常? – 2009-09-18 03:58:36
Sproc报告中生成的自定义错误,但是这应该是无关紧要的,因为我想处理这些错误,但没有解决它们。 – 2009-09-18 05:47:55