?
Solved

Turning Off Viewstate

Posted on 2007-11-21
4
Medium Priority
?
1,593 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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