Solved

Turning Off Viewstate

Posted on 2007-11-21
4
1,588 Views
Last Modified: 2013-11-07
Hi there,

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

I've tried:
<%@ Page EnableViewState="false" %>
and
<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?
0
Comment
Question by:quanmac
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:quanmac
ID: 20330883
I've also tried:
<asp:placeholder id="plhTasks" EnableViewState="False" Runat="server"></asp:placeholder>

and that didn't work either.
0
 
LVL 9

Accepted Solution

by:
daniel_balla earned 500 total points
ID: 20331662
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.

Cheers,
Dani
0
 
LVL 9

Expert Comment

by:daniel_balla
ID: 20331667
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
0
 
LVL 3

Author Comment

by:quanmac
ID: 20334826
Thanks Dani,

The Microsoft article was a big help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question