Precedence of settings such as viewstate at different levels
In ASP.NET, what is the order of pre开发者_StackOverflowcedence with setting viewstate and similar properties? These can be set at web.config, page level and also at the control. If I turn it off at both web.config (global), page level, but on at the control level, for example, what is the result?
Thanks
The Page
class is iterated through and each control's SaveViewState()
method is called. Therefore, if your Page
class has its EnableViewState
set to false, then this iteration will not occur and your controls will also have their viewstates disabled. That means if you want a control to have its viewstate enabled, then the page has to have its EnableViewState set to true.
If you want to turn the viewstate for most controls on a page off, then you'd have to find some sort of workaround. For example, you could create a small class which iterates goes through your control heirarchy and turns off the the viewstate for specified controls. Or, you could use some sort of container, and have that container's viewstate disabled, so that all its chiled controls are also disabled. Any controls you want to allow viewstate for can be placed outside the container. Both these methods would still require the Page's EnableViewState to be true.
精彩评论