ASP.NET: Why control state cannot be disabled

2019-02-25 18:59发布

I know ASP.NET doesn't allow to disable control state.

Does anybody know why? I've googled a lot but only saw it is not possible, but was not able to find "WHY?"

Any thoughts on this would be welcome!

P.S. In my particular case I need to put a lot of items into a dropdown list that will NOT be used for server side events. Instead of just disabling control state I need to write my own custom DropDownList... :(

1条回答
唯我独甜
2楼-- · 2019-02-25 19:29

Control state was separated from view state so that view state could be disabled without breaking critical functionality. In theory, control state should contain everything necessary for the server control to function properly.

Control state, introduced in ASP.NET version 2.0, is similar to view state but functionally independent of view state. A page developer can disable view state for the page or for an individual control for performance. However, 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.

http://msdn.microsoft.com/en-us/library/1whwt1k7(v=vs.100).aspx

However...ASP.Net does a poor job of making this distinction, and disabling view state will indeed break certain server controls despite the mandatory control state.

In your case, disabling view state for the dropdown list should remove the vast majority of state data; control state is usually quite small for a dropdown with view state disabled. I suggest trying it first before writing your own.

查看更多
登录 后发表回答