ASP.NET view state is a touchy subject. In recent years the entire concept of view state has been under scrutiny for it’s seemingly easy and endless abuse. But just as the baby should not be thrown out with the bath water, a mishandled tool does not render it useless.
Proper use of view state in ASP.NET pages can help performance (yes, I said help) and provide a number of other workflow and productivity benefits. This article’s aim is to dissect the differences between the WebDataGrid’s two view state properties: EnableDataViewState and EnableViewState.
Note: Before proceeding any further I strongly suggest that you read Dave Reed’s exceptional treatise on ASP.NET view state, TRULY Understanding ViewState as well as Scott Mitchell’s Understanding ASP.NET View State. These articles will set the foundation required to gain the proper perspective on how the grid’s view state flags work.
The concept of “data view state” was born from the Infragistics engineers’ desire to see view state handled correctly in the control. Traditionally ASP.NET controls place the values of nearly all properties into view state. Rather than stuffing all the grid’s data into HTML and ViewState, the WebDataGrid separates containers for data and any other of the grid’s properties. Therefore the only information placed in the DataViewState bag is the grid’s row collection. By default EnableDataViewState is set to false to ensure that data is included into view state upon explicit request.
Note: If you have DataViewState enabled along with the Paging behavior, only the current page’s row collection is tracked in the view state container.
While the WebDataGrid’s ViewState bag does not hold row collection information, it does keep track of style settings (CSS) and meta-data about the rows. Therefore if a user makes a customization to a row – the change in the row’s settings is maintained in ViewState even if the data itself is not persisted in the DataViewState bag. Taking this approach greatly reduces the view state maintained on a page.
By default the EnableViewState property is set to true.