Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my @page enableviewstate overiding the page's EnableViewsate in the web.config?

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.

like image 692
Jeff Martin Avatar asked Jun 18 '09 23:06

Jeff Martin


1 Answers

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.

like image 163
Jeff Martin Avatar answered Oct 13 '22 01:10

Jeff Martin