|
Report Application Server .NET SDK Developer Guide |
|
ViewState and persistence of the CrystalReportViewer object model |
ViewState is a browser-based approach in ASP.NET for persisting the state of the "view", that is, the Web Form. Its primary function is to support the persistence of Web controls.
Web controls (also called Web server controls) are modeled on Windows controls, which were introduced in Visual Basic. Windows controls are objects on the form that encapsulate a piece of display functionality, such as a text field, a button, or a table of data.
Web controls are similar to Windows controls. Like Windows controls, they operate on two levels: within the Web page, and in the code-behind class that supports the Web page. Similar to traditional controls in Windows Forms, Web controls encapsulate discrete pieces of display functionality into GUI objects: Button, TextField, DropDownList, DataGrid, and so on. In the code-behind class, these same controls are paralleled as classes that expose properties and methods.
A Web page is different from a Windows Form in that a Web page is a stateless environment. Therefore some kind of persistence mechanism is required to preserve the state of the Web page across page reloads.
ViewState maintains the state of controls on the Web page, much as Session maintains the state of instantiated objects on the server.
|
|
|
ViewState maintains the state of all Web controls automatically. This is achieved by having ViewState store each control based on the control's EnableViewState property (which defaults to True). |
Because ViewState stores the state of the data from the Web controls on the page, the entire ViewState object must be enclosed within the page as the page is transferred back and forth between the browser and the Web server. This is done by encrypting the entire ViewState object as a string, and then placing this string within the value of a hidden form tag on the page. For example, the ViewState for Web page that contains only a single button control might look like this:
[from the rendered HTML of an ASP.NET Web Form]
|
|
|
|
<input type="hidden" name="__VIEWSTATE" value="dDwtNTMwNzcxMzI0Ozs+I7GfLyg3p44eTLFCiVEiRKUBzFw=" /> |
|
ViewState stores only information that can be converted to string format.
The CrystalReportViewer control performs the role of report display for a Crystal report. It renders the report into HTML on the page along with a toolbar and tree view for manipulating the report display. The toolbar contains buttons to zoom, go to next page, print, export, and so on. The tree view expands to show nested grouping of data.
ViewState persists control information; therefore, it persists the state of all report display information (including toolbar and tree view events) for the CrystalReportViewer control across page reloads.
For example, if a user were viewing page 3 of the report and clicked the next page button in the toolbar of the CrystalReportViewer control, ViewState would persist the state of both pieces of information:
During page reload, the ViewState would restore the CrystalReportViewer control to page 3, and then restore the next page event click, causing the control to move the report ahead to page 4.
The CrystalReportViewer control performs an additional role: not only report display, but also a limited object model (contained in the CrystalReportViewer control class). This limited object model can be used for programmatic interaction with the report.
ViewState persists the state of both roles:
However, use of the CrystalReportViewer object model is generally discouraged, in favor of the more extensive ReportClientDocument (RAS) or ReportDocument object models. These alternate object models are not contained within the control, but are part of the class libraries in the corresponding SDKs.
|
|
|
For more information, see What best practices should I use when working with the CrystalReportViewer control?. |
If you use the CrystalReportViewer control to perform both roles (report display and object model), ViewState persists both of them, and you do not need any additional persistence mechanisms.
However, if you choose to use the CrystalReportViewer control only for the role of report display, and then bind the control to an external object model (such as ReportClientDocument or ReportDocument), a separate persistence mechanism is required to persist that external object model. Typically that second persistence mechanism is Session.
© 2021 SAP AG. All rights reserved.
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator