views:

508

answers:

3

Hi,

I have an asp:Gridview bound to an asp:ObjectDataSource. I have disabled the ViewState on the GridView, and have not set the DataKeyNames property. I have about 10 BoundFields and a few TemplateFields. These TemplateFields are not bound to server controls but to an anchor tag or to an img tag.

However, at runtime, when I switch on page tracing I see that the ControlState of the Gridview varies between 7 and 12K for displaying just 14 rows of data. (View source on the rendered page also gives a same long string in the __VIEWSTATE hidden field). I do not understand why this happens as I have enableViewState="false" on the gridview and, as said above, I am not using DataKeyNames. So, where is this Gridview ControlState coming from and is there a way to get rid of it?

Thanks in advance, Tim

+2  A: 

i think its normal because: control state cannot be disabled, Control state is designed for storing a control's essential data (such as a pager control's page number) that must be available on postback to enable the control to function even when view state has been disabled

note: By default, the ASP.NET page framework stores control state in the page in the same hidden element in which it stores view state. Even if view state is disabled microsoft said

that mean you actually saw the data of ControlState in _ViewState field which is ok because as microsoft said the ControlState of the control stored in viewstate even if you disable ViewState

peacmaker
Thanks for your answer. However, I find it strange that it needs 12K for just storing the page number and few other data.
Tim
A: 

If you're disabling viewstate, not using any postback controls within the gridview, and not doing paging/sorting, then you're probably better off using a repeater. Repeaters don't have to be placed inside a tag. So, the control state won't be an issue.

If you're using .net 3.5 you could also investigate using the ListView, which to me seems like a repeater / gridview hybrid.

ScottE
Hi and thanks for your answer. Are you saying that the Repeater does not use controlstate? Thanks
Tim
Tim - if it uses controls that require it, then yes. On it's own it probably doesn't - but I'm not 100% sure on that. The fact that it doesn't require being inside a server side form is a good clue.
ScottE
A: 

This article says that control state is actually stored in the __VIEWSTATE in a HybridDictionary.

Also, these articles say that even though you can set EnableViewState=false, you can never turn off ControlState (which is the point - so clients can't break your application):

JohnB