NET S TATE MANAGEMENT 95
State Data Management
Because both custom controls and the Page class inherit from Control, ViewState is easily accessible
to the ASP.NET developer from either the web form or from within a custom control class.
As described in the previous section, the type of the ViewState collection that is serialized into
the __VIEWSTATE hidden form field is System.Web.UI.StateBag, a strongly typed dictionary data
structure that stores name/value pairs with the value having a type that is either serializable or
has a TypeConverter defined.
Native data types such as int, string, and so forth have default TypeConverters that provide
string-to-value conversions, so no additional work is required on the part of the developer. In
situations where a developer creates a custom type for use in a server control, we recommend
that the developer create a TypeConverter class for the custom type in place of implementing
ISerializable. The reason is that types that are only defined as serializable are slower and
generate much larger ViewState than types that have a TypeConverter implemented. We discuss
how to create a TypeConverter in Chapter 11.
An alternative to implementing a TypeConverter is to customize how property data is
stored in ViewState.
Pages:
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177