The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

How to: Access the ASPxDocumentViewer and ASPxWebDocumentViewer Controls

  • 3 min to read

This example demonstrates how to access the ASPxDocumentViewer and ASPxWebDocumentViewer controls used to display reports in ASP.NET XAF applications.

In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).

When a user previews a report in an ASP.NET XAF application, a Detail View is displayed in a popup or main window (depending on the ReportsAspNetModuleV2.DesignAndPreviewDisplayMode value). This Detail View contains a single View Item which creates a web control used to display a report. The particular View Item and control types depend on the ReportsAspNetModuleV2.ReportViewerType property value (HTML5 or ASP).

ReportViewerType Value View Item Type Control Type
HTML5 ReportWebViewerDetailItem ASPxWebDocumentViewer
ASP ReportViewerDetailItem ASPxDocumentViewer

To access this View Item, implement a Controller that targets the ReportViewer_DetailView_V2 Detail View (this Detail View identifier is specified via the ReportsAspNetModuleV2.ReportViewDetailViewWebName constant). Pass the View Item type as the generic parameter of the CompositeView.GetItems<T> method. The first element of the returned list will be the required View Item, because there is a single report viewer item in the View. Then, you can handle the View Item's ViewItem.ControlCreated event and use the ReportViewer property to access the ASPxDocumentViewer or ASPxWebDocumentViewer control.

Example for an ASPxWebDocumentViewer (ReportViewerType is HTML5)

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2.Web;
// ...
public class CustomizeReportViewerController : ViewController<DetailView> {
    public CustomizeReportViewerController() {
        TargetViewId = ReportsAspNetModuleV2.ReportViewDetailViewWebName;
    }
    protected override void OnActivated() {
        base.OnActivated();
        ReportWebViewerDetailItem reportViewItem =  
            ((DetailView)View).GetItems<ReportWebViewerDetailItem>()[0] as ReportWebViewerDetailItem;
        reportViewItem.ControlCreated += delegate(object sender, EventArgs e) {
            // Access client-side events of the ASPxWebDocumentViewer control
            reportViewItem.ReportViewer.ClientSideEvents.Init = 
                "function(s, e) { s.previewModel.reportPreview.zoom(0.7); }"; 
        };
    }
}

Example for an ASPxDocumentViewer (ReportViewerType is ASP)

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2.Web;
// ...
public class CustomizeReportViewerController : ViewController<DetailView> {
    public CustomizeReportViewerController() {
        TargetViewId = ReportsAspNetModuleV2.ReportViewDetailViewWebName;
    }
    protected override void OnActivated() {
        base.OnActivated();
        ReportViewerDetailItem reportViewItem =  
            ((DetailView)View).GetItems<ReportViewerDetailItem>()[0] as ReportViewerDetailItem;
        reportViewItem.ControlCreated += delegate(object sender, EventArgs e) {
            // Access settings of the ASPxDocumentViewer control
            reportViewItem.ReportViewer.SettingsReportViewer.PageByPage = false;
        };
    }
}
Important

A reference to the DevExpress.XtraReports.v19.2.Web.dll assembly is required to compile these examples.