ASP.NET: Why control state cannot be disabled

后端 未结 1 1512
感情败类
感情败类 2021-01-21 19:58

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

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 20:23

    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.

    0 讨论(0)
提交回复
热议问题