Solved

Turning Off Viewstate

Posted on 2007-11-21
4
1,586 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Dani,

The Microsoft article was a big help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now