DEV Community

Cover image for How to View Reports in Your ASP.NET Webforms Application
Chelsea Devereaux for MESCIUS inc.

Posted on • Originally published at developer.mescius.com

How to View Reports in Your ASP.NET Webforms Application

What You Will Need

  • ActiveReports.NET
  • ASP.NET Webforms

Controls Referenced

  • WebViewer

Tutorial Concept

This blog post provides a step-by-step guide on how to embed the ActiveReports WebViewer control into an ASP.NET Web Forms application. It covers the necessary setup, adding reports, and configuring the WebViewer control to display reports in various formats like HTML, Acrobat Reader, and RawHTML.


ActiveReports.NET has established itself as a premier tool in the .NET ecosystem, consistently pushing the boundaries of what is possible in report generation and visualization. This enduring leadership stems from a commitment to providing a comprehensive suite of report types, catering to a wide range of reporting requirements, from straightforward data listings to complex, interactive dashboards. 

One of the key strengths of ActiveReports.NET lies in its versatile report viewer components, designed to seamlessly integrate with nearly every .NET platform. These components ensure that no matter the technological stack or project requirements, developers can deliver sophisticated reports with minimal friction, enhancing the user experience and facilitating data-driven decision-making. 

While our extensive blog library covers a variety of web-based report viewer components, this discussion will focus on a specific integration scenario: embedding the WebViewer control in an ASP.NET Web Forms application. The WebViewer control is particularly valuable for developers working within the ASP.NET Web Forms framework, offering a powerful tool to render and interact with reports directly within a web application. 

By detailing this process, we aim to equip you with the knowledge needed to seamlessly incorporate advanced reporting capabilities into your ASP.NET Web Forms projects, further extending the functionality and user engagement potential of your applications.

This blog will show how to embed the WebViewer control in an ASP.NET Web Forms application by completing the following steps:

Create the Application

First, we need to create a basic ASP.NET application. Once that is done, add the MESCIUS.ActiveReports.Web NuGet package to the project by right-clicking the References node and selecting Manage NuGet Packages. 

After successfully adding the NuGet package, add a new Web Form to the page and name it WebViewer.aspx. Open your Global.asax file to add the following code to the Application_Start():

    this.UseReporting(settings =>
                {
                    settings.UseFileStore(new DirectoryInfo(Server.MapPath("~/Reports")));
                    settings.UseCompression = true;
                }

    );
Enter fullscreen mode Exit fullscreen mode

Add a Report

In this blog, we will assume that you have existing Section, Page, or RDL reports. If you don't have existing reports, look at this page for walkthroughs on creating your first report with ActiveReports.NET.

Create a folder in the project to store your report files and name it Reports. Add your report files to this folder by right-clicking it and selecting Add→Existing Item...

Adding a report

Adding The WebViewer Control

Open the WebViewer.aspx page to add the WebViewer control by dragging and dropping from Visual Studio Toolbox. Adjust the size if you would like. In the Page_Load event, add the following code to pass a report to the viewer:

    protected void Page_Load(object sender, EventArgs e)
            {
                WebViewer1.ReportName = "menu.rdlx";            
            }
Enter fullscreen mode Exit fullscreen mode

Add the HTTP handler to the tags in your web.config as follows:

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <add verb="*" path="api/reporting/*" type="System.Web.Handlers.ScriptModule" name="nostaticfile" resourceType="Unspecified" preCondition="integratedMode" />
        </handlers>
    </system.webServer>
Enter fullscreen mode Exit fullscreen mode

You are done unless you want to specify a _ViewerType. _In ActiveReports.NET, when you embed a WebViewer control in an ASP.NET Web Forms application, you can specify the ViewerType to determine how the reports are rendered and displayed in the browser. The ViewerType setting controls the format and method by which the report content is delivered to the end-user.

The WebViewer has three different ViewerTypes: HTML (default), Acrobat, and RawHTML. 

HTML (Default) ViewerType 

The HTML ViewerType is the default option for the WebViewer. It renders the report as standard HTML elements, which makes the report highly interactive and easily viewable across different web browsers. 

Features: 

  • Offers dynamic interaction with the report, such as zooming, navigating through pages, and using parameters.
  • Provides good performance and compatibility across modern browsers.
  • Suitable for most standard reporting needs where interactivity and compatibility are important.

Acrobat ViewerType 

The Acrobat ViewerType renders the report as a PDF document, which is then displayed within the browser using Adobe Acrobat Reader or another PDF viewer. 

Features: 

  • Provides a print-ready format, ideal for high-fidelity reproduction of the report.
  • Useful when users need to download or print the report with precise formatting, including fonts and layout.
  • Requires the client browser to have a PDF viewer plugin or built-in PDF support.

RawHTML ViewerType 

The RawHTML ViewerType renders the report as plain HTML without the advanced interactive features available in the default HTML ViewerType.

Features: 

  • Provides a simpler, faster-loading version of the report.
  • Lacks the interactivity of the standard HTML ViewerType, focusing more on the content's static display.
  • Useful in scenarios where minimal JavaScript or simpler rendering is needed, such as when targeting older browsers or when quick loading times are crucial.

You can specify this in the Page_Load event as discussed above:

Viewer Types

Conclusion

Integrating ActiveReports into your ASP.NET Web Forms application significantly enhances its reporting capabilities, offering flexibility and ease of use. By following the steps outlined, you can effortlessly embed the WebViewer control and display various report types, making data presentation seamless for end-users. This approach not only simplifies report management but also ensures that your application can meet diverse reporting needs with minimal configuration. Explore more features and extend your reporting solutions by leveraging the full capabilities of ActiveReports.NET.

To see the complete implementation, download the sample.

*Before running the sample, clean the solution and then build the solution (not rebuild) to install the necessary packages.

Learn more about ActiveReports.NET features by visiting our Online Demos.

Top comments (0)