Skip to main content
A newer version of this page is available. .

Add the Document Viewer to an ASP.NET Web Forms Application

  • 2 minutes to read

Note

Watch the Video: Reporting: Web Viewer (YouTube)

This tutorial demonstrates how to add the Document Viewer to a web page in an ASP.NET Web Forms application:

  1. Open an application that contains a report or add a new report in Visual Studio.
  2. Expand the DX.21.1: Reporting Toolbox tab, drag the ASPxWebDocumentViewer control, and drop it onto a web page.

    drop-control-document-viewer-web-page

  3. Assign a report to the ASPxWebDocumentViewer control in one of the following ways:

    • Click the control’s smart tag, expand the drop-down list for the Report property, and select a report.

      aspx-web-doc-viewer-set-report

    • Specify the ReportSourceId property in the Properties window:

      aspx-web-doc-viewer-set-report-properties-window

    • Call the ASPxWebDocumentViewer.OpenReport or ASPxWebDocumentViewer.OpenReportXmlLayout method:

      using DevExpress.XtraReports.Web;
      //...
          protected void Page_Load(object sender, EventArgs e)
          {
              var cachedReportSource = new CachedReportSourceWeb(new XtraReport1());
              ASPxWebDocumentViewer1.OpenReport(cachedReportSource);
          }
      

    The OpenReport method’s parameter is the CachedReportSourceWeb object that generates a document and caches each generated page.

  4. Add the “resources” section to the application’s Web.config file with the following content to automatically load the required scripts:

    <devExpress>
        <!-- ... -->
        <resources>
            <add type="ThirdParty" />
            <add type="DevExtreme" />
        </resources>
    </devExpress>
    
  5. Use the control’s smart tag to specify the Session State property and enable the Document Viewer to use HttpContext (Session or User).

    This action adds handlers to the application’s Web.config file and registers them at the application startup in the Global.asax file:

    protected void Application_Start(object sender, System.EventArgs e) {
        DevExpress.XtraReports.Web.WebDocumentViewer.Native.WebDocumentViewerBootstrapper.SessionState = 
            System.Web.SessionState.SessionStateBehavior.Required;
    }
    
  6. You can customize the Web Document Viewer.

  7. Run the application to view the Document Viewer in a web browser.

    get-started-web-document-viewer-result

    For troubleshooting, review the following topic: Document Viewer Requirements and Limitations

See Also