Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 28, 2009 08:35 PM by XIII
May 22, 2009 08:08 PM|LINK
In all of my web user controls that I need to persist information during postback, I always create a ViewState Property. I just watched the video #27 of the General ASP.Net learn and they suggest to use the "Control State". This is the first I have ever
heard of this and I am confused on why you want to use the Control State over the View State. Can anyone please shed some light on this for me? I take it that the Control State is not stored in the ViewState when rendered to the page? I'm lost on this Control
State stuff!! :)
May 22, 2009 08:32 PM|LINK
when you use viewstate in your controls a developer using your control could opt to turn viewstate off which could end up that your control doesn't behave properly anymore. Controlstate on the other hand can't be turned off by a developer using your control.
However you as a control designer should make sure that you don't abuse this feature. Only put the ultimate necessary stuff inside control state.
May 22, 2009 08:44 PM|LINK
That is really the only difference then? Also if you have the viewstate enabled on the page and you dont store anything in the viewstate would it really run any different then having the viewstate disabled?
May 22, 2009 08:51 PM|LINK
take a look at this example:
Control state vs viewstate.
May 28, 2009 04:14 PM|LINK
So I'm assuming that if we're writing controls that aren't going to be distributed and we don't foresee turning off ViewState, then we should just use ViewState for all our needs? I'm hoping that's the answer because that's what I've been doing :-D
May 28, 2009 08:35 PM|LINK
only put those things in control state that your control always need when having the need to persist something. If you know that persistance is a nice feature but that a developer can do without use viewstate. So yes most of the time you'll be using viewstate.