Share via


Tutorial: Persisting the ReportDocument Object Model Using Session

In this tutorial, you use the ReportDocument object model and make programmatic changes to a report at runtime. You also learn how to use Session to persist those changes across Web page reloads.

Because only Web applications require Session persistence, this tutorial does not apply to Windows projects.

Note

For an overview of persistence, see Which Persistence Approach Should I Use with Crystal Reports? under SDK Fundamentals.

Introduction

The project that you create in this tutorial uses a Web Form that contains a CrystalReportViewer control and two buttons that change the sort order of the report within the ReportDocument object model.

First, you construct the project without Session persistence. Without persistence, you can see that the change in sort order lasts no longer than a button click event.

Then, you add Session persistence to the project. The ReportDocument instance is placed into Session at the time of creation, and at any point where the state of the ReportDocument instance is changed.

Whenever the report needs to be redisplayed, the ReportDocument instance is pulled out of Session and bound to the CrystalReportViewer control. This guarantees that every time the report is displayed, the user views the most up-to-date version of the ReportDocument instance.

Note

In this tutorial you use Session, because you will persist modifications to the ReportDocument object model. If you plan to use only the limited object model contained within the CrystalReportViewer control, use ViewState exclusively.

When using Session to persist a ReportDocument object, are any other persistence models involved?

When using Session to persist a ReportDocument object, are any other persistence models involved?

Yes. In an ASP.NET Web application, objects typically use Session for persistence, while Web server controls use ViewState for persistence. Because a Crystal Reports for Visual Studio Web application uses objects and Web server controls to interact with reports, persistence is shared by Session and ViewState:

  • Session persists the ReportDocument object model, which interacts with the report programmatically at runtime.
  • ViewState persists the CrystalReportViewer control, which displays the report. In particular, ViewState persists the display properties that are set in the toolbar of the CrystalReportViewer. ViewState also persists any events (such as zoom, NextPage) that are triggered from buttons in the toolbar.

ViewState persistence is managed automatically. Therefore, in this tutorial you only code Session persistence.

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Web Site: CS_Web_RDObjMod_Session
  • Visual Basic Web Site: VB_Web_RDObjMod_Session

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section:

See Also