Why is my @page enableviewstate not overriding the EnableViewsate page in the web.config file?

I want to disable viewstate for almost all of my pages, and I used the element for this in my web.config.

On a page that specifically uses viewstate, I used EnableViewState = true. However, the page does not work, and dropdownlists that depended on the viewstate are not populated in the postback.

To try to find the template, I was able to specify a DISABLE viewstate at the page level, while web.config was set to true, but I cannot do the opposite where web.config is set to false, and the page is set to true

Any ideas on anything else that might be conflicting?

UPDATE: I created a new empty project to experiment with this, and apparently either ASP.NET is broken or it is not designed to work that way. If I enableViewState = false in web.config, I cannot enable it at the page level. However, if I set it to true, I can disable it at the page level.

UPDATE UPDATE: I got it to work on an empty project. Not quite sure what has changed, which made it work all of a sudden. Now I have set the web.config parameter to false, and the page is set to true, and the page saves the viewstate over the postback. This means that it is something specific to my larger, more complex project.

+7
viewstate
source share
2 answers

So the answer is that if you change the main page on the page without setting the EnableViewState property for MasterPage to the EnableViewState page, you will get the behavior described in the question.

There is an HttpModule that modifies MasterPage based on some criteria set by other parts of the application. By setting MasterPage.EnableViewState = Page.EnableViewState in the OnInit property of the main page, I was able to restore the expected behavior.

+4
source share

From what I observed in .NET 2.0, disabling ViewState at the page or application level will disable it for all children, regardless of which children indicate in enableviewstate properties.

If you want to use viewstate, even for a single control, you cannot set enableviewstate to false at the page or application level.

0
source share

All Articles