即使禁用视图状态且不使用 DataKeyNames,Gridview ControlState 也非常大 [英] Gridview ControlState very large even when viewstate disabled and not using DataKeyNames
问题描述
我有一个绑定到 asp:ObjectDataSource 的 asp:Gridview.我在 GridView 上禁用了 ViewState,并且没有设置 DataKeyNames 属性.我有大约 10 个 BoundFields 和一些 TemplateFields.这些 TemplateField 不绑定到服务器控件,而是绑定到锚标记或 img 标记.
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.
但是,在运行时,当我打开页面跟踪时,我看到 Gridview 的 ControlState 在 7 到 12K 之间变化,仅显示 14 行数据.(呈现页面上的查看源代码也在 __VIEWSTATE 隐藏字段中给出了相同的长字符串).我不明白为什么会发生这种情况,因为我在 gridview 上有 enableViewState="false" ,并且如上所述,我没有使用 DataKeyNames.那么,这个 Gridview ControlState 来自哪里,有没有办法摆脱它?
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?
提前致谢,提姆
推荐答案
我觉得很正常,因为:控件状态不能被禁用,控件状态被设计用于存储控件的基本数据(例如分页控件的页码),这些数据必须在回发时可用,以便即使在视图状态已禁用的情况下也能使控件起作用
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
注意:默认情况下,ASP.NET 页面框架将页面中的控件状态存储在它存储视图状态的同一隐藏元素中.即使视图状态被禁用微软说
这意味着你实际上在_ViewState字段中看到了ControlState的数据,这没问题因为正如微软所说,即使您禁用了 ViewState,控件的 ControlState 也会存储在 viewstate 中
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
这篇关于即使禁用视图状态且不使用 DataKeyNames,Gridview ControlState 也非常大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!