views:

103

answers:

1

hi


1) What properties ( if any ) do controls like GridView and TextBox save in control state? BTW - I assume these controls have their control state enabled by default?!


2) Control needs to call Page.RegisterRequiresControlState ( during Init event ) in order to signal that its control state needs to be persisted.

Assuming control A (A is of type WebControl2) needs to save its control state and that A is contained inside control B ( B is of type WebControl1 ) --> I was able to register A’s control state by overriding B’s OnInit method:

protected override void OnInit(EventArgs e)
{
    Control control= this.FindControl("A");

    Page.RegisterRequiresControlState(control);
    base.OnInit(e);
}


Is this considered a bad programming practice?


thanx

+1  A: 

Hey,

If you are looking for a lot of control definitions, check out .NET reflector, a free tool that allows you to inspect this. For GridView, I know it has editindex, pageindex, selectedindex, sortexpression, sortdirection, datakeynames, pagecount in control state. I don't think TextBox uses control state.

Only store essential properties in control state. I don't know what benefit tapping into another control's state is going to do, because the actual values that get loaded and saved in control state have to be done in protected LoadControlState and SaveControLState methods. Values do not automatically get saved in control state if enabled.

Brian
"Values do not automatically get saved in control state if enabled" I realize that, but I thought that perhaps there were some benefits of parent control being able to enable the control state of a nested control. Anyways, thank you for helping me
carewithl
What I mean is that you have to use variables that get loaded or saved within the LoadControlState and SaveControlState, so that even if you enable it in a parent control, if the control doesn't read/write from control state, it doesn't provide any benefit, unfortunately.
Brian