Prev | Current Page 236 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

SaveViewState() : null;
object[] state = new object[3];
state[0] = baseState;
state[1] = labelStyleState;
state[2] = textboxStyleState;
return state;
}
The first thing we do in the code is call WebControl??™s version of SaveViewState() to ensure
we don??™t break any behavior implemented in the base class. Calling base.SaveViewState()
persists state information, including the values in the ControlStyle property. Next, we persist the
styling information for the label and text box into ViewState. This is accomplished by casting the
Style instances to the IStateManager interface on the Style class so that we gain access to the
SaveViewState() method. Finally, we package the three object state binary large objects (BLOBs)
into an object array that the ASP.NET framework persists into ViewState.
Retrieving style information from ViewState performs these steps in reverse. Our
LoadViewState() method is as follows:
override protected void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] state = (object[])savedState;
if (state[0] != null)
base.LoadViewState(state[0]);
if (state[1] != null)
((IStateManager)LabelStyle).LoadViewState(state[1]);
if (state[2] != null)
((IStateManager)TextboxStyle).


Pages:
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248