R – What properties ( if any ) do controls like GridView and TextBox save in their control state

asp.netnetuser-controlswebforms

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

Best Answer

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.