views:

430

answers:

2

I want to disable viewstate for nearly all of my pages and I have used the element to do so in my web.config.

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

In an effort to try to find a pattern I was able to specifically DISABLE viewstate on the page level while the web.config was set to true, but I can't seem to do the reverse where the web.config is set to false and the page is set to true.

Any ideas on something else that may be conflicting?

UPDATE: I created a new blank project to experiment with this and apparently either ASP.NET is broken or it wasn't intended to work this way. If I enableViewState=false in the web.config I can't turn it back on at the page level. However if I set it to true, I can turn it off at the page level.

UPDATE UPDATE: I got it to work in the blank project. Not exactly sure what changed that made it work suddenly tho. I now have the web.config set to false and the page set to true and the page retains viewstate over a postback. This means it is something specific to my bigger, more complex project.

A: 

From what I have observed in .NET 2.0, disabling the ViewState at a page or application level will disable it for all child elements, regardless of what the child elements specify in their enableviewstate properties.

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

Mike
This is not correct. I have created a blank project (as shown in my update) and the behavior is as expected, if the web.config is set false but the page is set true, viewstate works.
Jeff Martin
A: 

So the answer is that if you change the masterpage on the page without setting the EnableViewState property of the MasterPage to the EnableViewState of the page, then you get the behavior described in the question.

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

Jeff Martin
I know this is old, but I had to do `Page.Master.EnableViewState = Page.EnableViewState`
Nelson