开发者

Gridview ControlState very large even when viewstate disabled and not using DataKeyNames

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 t开发者_高级运维he 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


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


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.


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):

  • Control State vs. View State Example

  • ASP.NET State Management Overview

  • ASP.NET State Management Recommendations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜