Handling Report Exceptions with ASP.NET ReportViewer in Remote and Async Mode

I have a report page that uses the Microsoft.Reporting.WebForms.ReportViewer component to display Report Server (SSRS) reports asynchronously. Currently, if an error occurs, the message is displayed inside the ReportViewer control.

I want to add my own error handling logic so that the user gets a friendly message. How can I achieve this and still run the viewer in Async mode while reporting to the SSRS server?

Listening for the ReportViewer.HandleError event will not work because the page back of the page has completed.

+2


source to share


1 answer


After checking JavaScript ReportViewer, I came up with the following solution. It is susceptible to violation if Microsoft changes this particular method. The following code will be added to the page header to ensure that it runs after the ReportViewer JavaScript message is loaded, but before the RSClientController instance is instantiated.

// 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;

      



Source code from Microsoft ReportViewer script file (inside 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;

      

+1


source







All Articles