Using the ViewState Property

In some cases, you do not need to maintain state across pages but rather only between calls to the same page. If you need to do this, you can use a StateBag object provided by ASP.NET.

Using the StateBag Object

You can use the ViewState property of the page. The ViewState property is a StateBag object. That is, the property is defined As StateBag. In the Web page shown in Figure 23.1, you input three values. You can submit them to the server and display some data in the Result label. At the same time, you create three variables in a “state bag” using the ViewState object.

Figure 23.1. Use this screen to test the StateBag object.

In the Click event procedure of the Create State button, write the following code to display ...

Get ASP.NET Developer's JumpStart now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.