ControlState in ASP.NET V2

Fredrick has a great post about the new ControlState feature in ASP.NET V2:

    http://fredrik.nsquared2.com/viewpost.aspx?PostID=265

It's still not 100% clear to me what the use case is for ControlState.  I think that control developers should always use it as opposed to ViewState when persisting properties and data etc.

 

2 Comments

  • That wouldn't be a good idea.



    Consider a scenario: DataGrid preserved the rows in ViewState and current page displayed. You need to prevent data from being cashed in ViewState but keep the page displayed. That's where ControlState comes in. It keeps the state of the control and ViewState should be used for carrying "optional" data.



    Meaning that without "cetrain" data the functionality of a control breaks and therefor must always be carried over.



    Hope this explains it a bit.



    Alex

  • To follow up on what Alex said, with ViewState today it's an "all or nothing" thing from the page developer's perspective. If he turns off view state, he loses ALL state persistence across postback - both the optional stuff (Font, colors, etc.) and the vital stuff. ControlState provides a means for a control developer to split up the optional and necessary, giving the page developer more flexibility on controlling page size via turning off view state.

Comments have been disabled for this content.