ASP .NET 2.0 Control State vs ViewState

扶醉桌前 提交于 2019-12-08 10:23:10

问题


Is the new ControlState feature only applicable to custom controls or is it available for the standard server controls as well?

That is..can you disable ViewState for an entire page with standard controls like Detailsview, Gridview and would it still work? Does ControlState apply to standard server controls?

Or in order to work with ControlState for standard server controls you have to modify their behavior by creating a new custom GridView/DetailsView?


回答1:


From the Microsoft Documentation.

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.

From this you can guess that GridView and other items would not be storing that large of an amount of information in ControlState, so I'm guessing that if you wanted to do it, against Microsoft's recommendation you would have to extend the base control to do it.




回答2:


You can disable view state for all page but you need to rebind datagrid, dataview in every postback.

Sometimes it works better then saving a huge viewstate on the client.

For standard server controls: if you modify Control Properties after init, then all modifications will be saved in ViewState too.

Here is awesome Scott Mitchell Post about ViewState.



来源:https://stackoverflow.com/questions/381369/asp-net-2-0-control-state-vs-viewstate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!