However, if ViewState is disabled
for the individual control or the whole page, control state is still persisted. This allows developers
to store state related to basic control functionality in control state without having to
enable ViewState.
Server control developers have a responsibility to appropriately use control state for the
behavioral state of a control only, and not use it for all states including content. To demonstrate
a good use of control state, we??™ll enhance the TextBox3d class from Chapter 2 to support control
state for its Enable3D property, so ViewState is not required but the control still functions as
expected without ViewState enabled.
New TextBox3d Demonstration Web Form
Let??™s copy the TextBox3d class into the ControlsBook2Lib.Ch03 namespace as our starting point
for updating the server control to support control state for the Enable3D property. We??™ll also
copy the demonstration page for the original TextBox3d control and update it to include an
instance of our new version of TextBox3d that supports control state. Figure 3-14 shows the
TextBox3DControlStateDemo web form at design time.
When this web form is run with the EnableViewState property on the page or on both controls
set to true, the Toggle3d button dutifully toggles the Enable3D property on both controls, and
pressing the Submit button results in the expected postback with state maintained for both
controls.
Pages:
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204