views:

814

answers:

2

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

I want to add custom error handling logic so that the user gets a friendly message. How can I achieve this and still run the viewer in Async mode, rendering the reports on the SSRS server?

Listening to the ReportViewer.HandleError event won't work as the page postback has already completed.

+1  A: 

After inspecting the ReportViewer JavaScript, I came up with the following solution. It's prone to breaking things if Microsoft changes this particular method. The following code would be added to the header of the page to make sure it runs after the ReportViewer javascript is loaded, but before an instance of the RSClientController is created.

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

The original code from the Microsoft ReportViewer script file (inside the Microsoft.ReportViewer.WebForms, 8.0.0.0, .Net Framework 3.5 SP1) is:

function OnReportFrameLoaded()
{
    this.m_reportLoaded = true;
    this.ShowWaitFrame(false);

    if (this.IsAsync && this.m_reportObject != null)
        this.m_reportObject.OnFrameVisible();
}
RSClientController.prototype.OnReportFrameLoaded = OnReportFrameLoaded;
Robert Wagner
Good idea. We can use this ourselves..
gbn
A: 

Hi, I wan't to display error on same page in some lable. how can i find the error text?

Jawad
You could write a Javascript function that takes the error as a parameter, and then finds the named span tag on the page and sets the contents. The code above would then call this function (or even do it in the code above).
Robert Wagner