0

I want to disable viewstate for my entire site, but on some pages I want to enable it.

in my masterpage "main.master" I have EnableViewState="false" in my contentpage, which has main.master as its masterpage I have EnableViewState="true"

This doesnt seem to work, the viewstate remains disabled.

So I tried some other combinations:

master: enable content: disable -> results in enabled viewstate

master: enable content: disable via code-behind (Me.Master.EnableViewState = False) -> results in enabled viewstate

It seems as if the masterpage is always overruling the contentpage, no matter what I do.

How can I disable the viewstate for the entire website, bu enable it for individual pages (I saw another issue here, but its also unsolved: http://codeasp.net/blogs/vivek_iit/microsoft.net/26/masterpage-and-viewstate-issue)

Adam
  • 6,041
  • 36
  • 120
  • 208

2 Answers2

1

You may find this helpful:

Starting a new web project, I always disable viewstate by default. If I need it later, I’ll enable it on a page-by-page basis.

To do this in web.config:

<pages enableViewState="false">
...
</pages>

This IS case-sensitive. Not sure why.

Source: Disabling ViewState in web.config

mellamokb
  • 56,094
  • 12
  • 110
  • 136
atoMerz
  • 7,534
  • 16
  • 61
  • 101
  • I added enableViewState="false" in web.config,but as a commenter on your link page already mentioned: it doesnt seem to work when there's a form in the masterpage. So the viewstate is now still loaded...what can I do? – Adam Jan 03 '12 at 21:08
  • Search on google, there are a number of links there, I'm just pasting one: http://www.ironspeed.com/articles/Disable%20View%20State%20for%20a%20Page/Article.aspx – atoMerz Jan 04 '12 at 09:26
  • [Don't answer with just a link.](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers) – mellamokb Jul 27 '12 at 12:59
0

Set enableViewState="false" in the <pages> element in Web.config instead of the master page.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • On this page its discussed, but it seems its an issue with asp.net: http://odetocode.com/blogs/scott/archive/2006/10/11/masterpage-issue-with-viewstate-disabled-in-web-config.aspx or is there a fix by now? – Adam Jan 03 '12 at 21:10