• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1601
  • Last Modified:

Turning Off Viewstate

Hi there,

I was wondering, how would I be able to turn off the viewstate on a page?

I've tried:
<%@ Page EnableViewState="false" %>
<form runat="server" enableviewstate="false">

And both of them didn't get rid of the viewstate. When I went to the page and viewed the source, I still got:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ5OTgwMDQ0OWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFhUFB3JkYkRhdGUFBnJkYkNhdAUGcmRiQ2F0BQdyZGJSb2xlBQdyZGJSb2xlBQdjaGtFdm50BQtjaGtJbmhFdmVudAUHcmRiQ29kZQUHcmRiQ29kZQULY3RsMDMkY3RsMDAFC2N0bDA0JGN0bDAwBQtjdGwwNSRjdGwwMAULY3RsMDYkY3RsMDAFC2N0bDA3JGN0bDAwBQtjdGwwOCRjdGwwMAULY3RsMDkkY3RsMDAFC2N0bDEwJGN0bDAwBQtjdGwxMSRjdGwwMAULY3RsMTIkY3RsMDAFC2N0bDEzJGN0bDAwBQtjdGwxNCRjdGwwMOe1J6wNaf1luvIBPPN4nWBmBiwy" />

I am trying to disable the viewstate in order to make the page load faster, because I won't need to keep the state of the controls on the page, I wanted to disable it.

Anyone have any ideas?
  • 2
  • 2
1 Solution
quanmacAuthor Commented:
I've also tried:
<asp:placeholder id="plhTasks" EnableViewState="False" Runat="server"></asp:placeholder>

and that didn't work either.
Hi there.
As soon as you've set the <%@ Page EnableViewState="false" %> the viewstate of the page (and any/all controls contained in that page) is off. That means that none of these controls will not save (or read) the viewstate. However, the underlying framework (the form object to be more precise) will still supply the means for the viewstate (just the barebone) and that is the hidden field you see in the html source of your page.
Actually, it is a collection of 3 values, first one being the page hash, second is the sum of all the viewstates of every control in the page (which is the very content of the viewstate and would be empty in your case) and the third being an array of all the registered controls that require a postback. You can see these values for yourself as by default the viewstate is not encrypted and it is just a base64 encoded string. So if you copy paste that content and decode it you will be able to read it.
To sum it up, it is a good practice to turn off viewstate (if you are sure it is not needed) as it will reduce the size of your page. As you have it, it is the minimal size. If you would enable it, the value of this hidden field (its content) would increase, therefore the total size of your html would increase.
Hope this helps.

P.S. if you want to read more about the viewstate, I recommend this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp
Also, if you want to play with the base64 encoded strings, this might help: http://www.motobit.com/util/base64-decoder-encoder.asp
quanmacAuthor Commented:
Thanks Dani,

The Microsoft article was a big help.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now