I am working with a RadListBox. RadListBox has the following property which is set to True by default: PersistClientChanges
The functionality of this property is dependent on ViewState. That is, when a change is made client-side, the changes are stored into the ViewState model for the control — and then during next postback the ViewState is parsed, the changes ‘re-run’ and applied to the control server-side.
Unfortunately, I do not have ViewState enabled on my page, and I’m not really trying to have it enabled, either. That being said, I want this functionality. So, I am looking at my other options.
The MSDN documentation states “Use control state only for small amounts of critical data that are essential for the control across postbacks. Do not use control state as an alternative to view state.”
And I am wondering:
- What counts as a small amount of critical data? A bool? A small list of items? Less than 10000 data points??
- What kind of gotchas should I be aware of? Is this a dumb path for me to following? Etc..
Just any other information on using ControlState properly would be nice. Thanks.
First i must admit that i’ve never used
ControlStateto persist values across postbacks.But control developers who create Controls that are used by other developers might want to use it to ensure functionality even if
ViewStateis disabled. Otherwise disabling would result in incorret behaviour or errors that are not obvious.So in my opinion you would use
ControlStateif you would normally useViewStatebut you must ensure that the control also works whenViewStateis disabled.In this case the sentence “Do not use control state as an alternative to view state” would be wrong, because you should use ViewState as well only for small amounts of data that must be persisted across postbacks.
An example to clarify what i mean:
Consider you want to create a custom control that inherits
GridView. You can store the data inViewStateto maintain values across postbacks. You should allow to disable theViewStateon your control without any problems, you should not rely on the fact that it’s enabled, because developers who are using your control might want to reduce network traffic. But you could provide other properties that are stored inControlStatelike SortDirection, PageIndex, DeleteButtonText etc. that you think are important and are single values, therefor less resource intensive than storing allGridViewRows.Edit: According to your actual problem:
You could enable ViewState for some controls and disable it for others, but you cannot disable it for whole page and enable it for child-controls in this page.
Enable ViewState for few controls and disable for others/page
Edit: Here is an extension to enable/disable ViewState for all child-controls(VB.NET)
You can call it: