Export (0) Print
Expand All

Microsoft.Reporting.WebFormsClient.ReportViewer Class

Provides properties and methods for client-side programming of the ReportViewer Web server control.

The ReportViewer Web server control creates an instance of this class in the client browser as a handle for you to programmatically interact with the client-side control. Use this instance to customize the behavior of the client-side control with minimal postbacks to the server.

Namespace: Microsoft.Reporting.WebFormsClient

Inherits: Sys.Component


var v = $find(viewerId);

Name Description

Microsoft.Reporting.WebFormsClient.ReportViewer.exportReport Method

Exports the report to the specified format.

Microsoft.Reporting.WebFormsClient.ReportViewer.find Method

Searches for a string in the current report in the report area.

Microsoft.Reporting.WebFormsClient.ReportViewer.findNext Method

Finds the next search hit in the report.

Microsoft.Reporting.WebFormsClient.ReportViewer.invokePrintDialog Method

Launches the Print dialog box.

Microsoft.Reporting.WebFormsClient.ReportViewer.recalculateLayout Method

Recalculates the layout of the ReportViewer.

Microsoft.Reporting.WebFormsClient.ReportViewer.refreshReport Method

Refreshes the report.

Microsoft.Reporting.WebFormsClient.ReportViewer.documentMapCollapsed Property

Gets or sets a Boolean value that indicates whether the document map is collapsed.

Microsoft.Reporting.WebFormsClient.ReportViewer.isLoading Property

Gets a Boolean value that indicates whether the Web page is performing a postback or client-side control is loading content.

Microsoft.Reporting.WebFormsClient.ReportViewer.promptAreaCollapsed Property

Gets or sets a Boolean value that indicates whether the parameter prompt area is collapsed.

Microsoft.Reporting.WebFormsClient.ReportViewer.reportAreaContentType Property

Gets a Microsoft.Reporting.WebFormsClient.ReportAreaContent enumeration value that indicates the current content type of the report area.

Microsoft.Reporting.WebFormsClient.ReportViewer.reportAreaScrollPosition Property

Gets or sets a Sys.UI.Point object that represents the scroll position of the report area.

Microsoft.Reporting.WebFormsClient.ReportViewer.zoomLevel Property

Gets or sets a string that represents the current zoom level.

You do not create an instance of the ReportViewer class directly. Instead, you access the ReportViewer instance. The ReportViewer instance is created every time the Web server control is rendered in the client browser and persists as long as the Web page is open in the browser and the Web server control is not rerendered. If the ReportViewer Web server control is placed inside an UpdatePanel control, the ReportViewer instance is disposed and recreated every time the update panel is refreshed in the client browser by a partial-page update.

To access the ReportViewer instance, use the Sys.Application.findComponent method or the $find shortcut with the ID of the ReportViewer instance. For example, the ASP.NET page snippet below registers the JavaScript file, ClientCode.js, in the ScriptManager control. The ClientCode.js file then defines a rezoom method that uses the $find method to access the ReportViewer instance using the client-side ID of the ReportViewer Web server control. Adding script references to the ScriptManager control ensures that registered scripts are executed after the Microsoft AJAX Library is loaded.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="ClientCode.js" />
    </Scripts>
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote">
    <ServerReport ReportPath="/AdventureWorks 2008 Sample Reports/Company Sales 2008" 
        ReportServerUrl="http://<servername>/reportserver" />
</rsweb:ReportViewer>
<asp:TextBox ID="TextBox1" runat="server" onchange="rezoom(value)"></asp:TextBox>

The code for ClientCode.js is shown below. In most cases, the value of the viewerID variable is the ID of the Web server control in the ASP.NET page. In the ASP.NET snippet, this is "ReportViewer1". You should use the Web server control's ClientID property to reliably obtain the client-side ID.

function rezoom(level) {
    var viewer = $find("ReportViewer1");
    if (!viewer.get_isLoading() && viewer.get_zoomLevel() != level)
        viewer.set_zoomLevel(level);
}

When the Web page is performing a postback or the client-side control is loading content, accessing the methods or properties of the ReportViewer instance will cause an exception with the message: "The report or page is being updated. Please wait for the current action to complete." The isLoading property can be used to check whether the report or page is being updated and whether you can access the methods and properties. This property does not throw an exception.

When the Web page or the client-side control is not performing a postback, a set of methods require that a report is loaded. If no report is loaded, invoking those methods will cause an exception with the message: "The operation cannot be performed because there is no report loaded." These methods are listed below. Use the reportAreaContentType property to check whether the report area contains a report page before you use these methods.

If you want to be notified when a property is changed, register an event handler with the Sys.Component.propertyChanged event. This is an event of the ReportViewer instance's base class. For example, the following code registers an event to enforce a restriction on the value of the zoomLevel property. You can add a script reference to the following JavaScript code in your ScriptManager control.

Sys.Application.add_load(function () {
    $find(viewerID).add_propertyChanged(viewerPropertyChanged);
});

function viewerPropertyChanged(sender, e) {
    if (e.get_propertyName() == "zoomLevel") {
        var viewer = $find(viewerID);
        if (!viewer.get_isLoading() && viewer.get_zoomLevel() < 20) {
            viewer.set_zoomLevel(20);
            alert("Reset zoomLevel to 20.");
        }
    }
}

Properties changes that occur before the add_propertyChanged method will not invoke the event handler. Make sure that you place the add_propertyChanged method correctly so that the event is handled as expected. For most scenarios, you can register with propertyChanged inside an event handler for the Sys.Application.load event, like the code example above. However, since the client-side control also executes code in the load event, its add_load handler may change the property of interest to you before your add_load handler is executed, depending on the order in which the AJAX client-side framework executes the add_load handlers. To ensure that all property changes are handled, you can register with propertyChanged in an event handler for the Sys.Application.init event.

Show:
© 2014 Microsoft