Add the Document Viewer to an ASP.NET Web Forms Application
- 2 minutes to read
Step-by-Step Guide
This tutorial demonstrates how to add the Document Viewer to a web page in an ASP.NET Web Forms application:
- Open an application that contains a report or add a new report in Visual Studio.
Expand the DX.24.2: Reporting Toolbox tab, drag the ASPxWebDocumentViewer control, and drop it onto a web page.
Rebuild the project. 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.
The following markup is generated:
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server"> <dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewer1" runat="server" ReportSourceId="WebFormsExample.Reports.XtraReport1" > </dx:ASPxWebDocumentViewer> </asp:Content>
Specify the ReportSourceId property in the Properties window:
Instantiate a report and call the ASPxWebDocumentViewer.OpenReport(XtraReport) method:
using DevExpress.XtraReports.Web; //... protected void Page_Load(object sender, EventArgs e) { ASPxWebDocumentViewer1.OpenReport(new DXWebApplication1.XtraReport1()); }
Create a class that implements the IReportProvider interface, and register it as a service at startup. Call the OpenReport(String) method:
using DevExpress.XtraReports.Web; //... protected void Page_Load(object sender, EventArgs e) { ASPxWebDocumentViewer1.OpenReport("TestReport"); }
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>
Run the application to view the Document Viewer in a web browser.
Troubleshooting
Review the following help topic: Document Viewer Requirements and Limitations
Customization
Review the following help topic for information on how you can customize the Web Document Viewer: Document Viewer Customization (ASP.NET Web Forms).