Solved

Turning Off Viewstate

Posted on 2007-11-21
4
1,589 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
REXEX help Part 2 2 39
VB.Net Tranfer data between to VB.Net apps 8 40
How to read text with RegEx... 2 25
call a controller action method from Global.asax in asp.net 1 20
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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