Supporting View State
You can use the ViewState
property of the Control
or Page
class to add values to View State. The ViewState
property exposes a dictionary of key and value pairs. For example, the following statement adds the string Hello World!
to View State:
ViewState["message"] = "Hello World!"
Technically, you can add an instance of any serializable class to View State. In practice, however, you should add only simple values to View State, such as Strings
, DateTimes
, and Integers
. Remember that anything that you add to View State must be added to the hidden __VIEWSTATE
form field. If this field gets too big, it can have a significant impact on your page’s performance.
The control in Listing 36.12 has two properties: Text
and ViewStateText ...
Get ASP.NET 4 Unleashed 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.