-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: mygoodwill770521
Message 1 in Discussion

Improving page performance. By trimming the view state where you can live 
without it you do yourself and others a favor by reducing payload and improving 
page performance. ASP.NET view state is a great feature and an essential tool 
for web development of today. It maintains the state of a page as it travels 
back and forth. There is no more need to worry about restoring values of page 
controls between postbacks. The view state of a page is, by default, placed in 
a hidden form field named __VIEWSTATE. This hidden form field can easily get 
very large, on the order of tens of kilobytes. Not only does the __VIEWSTATE 
form field cause slower downloads, but, whenever the user posts back the Web 
page, the contents of this hidden form field must be posted back in the HTTP 
request, thereby lengthening the request time, as well. The web is stateless, 
For example, you request an ASP.NET page from a web server. Once the page is 
processed on the server and returned to you that same server does not remember 
the page anymore. Even a slight page postback initiates the same request 
sequence and the web server performs the same task again as if it never saw 
this page in the first place. This is the grand difference between web 
applications and their desktop counterparts. On the desktop you can maintain 
state between requests. On the web it�s a much harder task View state is simply 
text. It is an aggregate of values of controls on a page. It's a string that 
contains values of page controls hashed and encoded in some manner. The view 
state contains no information about the server or the client. It only comprises 
information about the page itself and its controls. It lives along with the 
page in the user's browser.
If you view the source of an ASP.NET web form you will see something like this:
<input type="hidden" name="__VIEWSTATE" 
            value="CEbzzzEnmmz+Bc8IDFlnpgCLJ/HB00...>
Every server control ultimately derives from the Control class. Be it a 
WebControl, HtmlControl or even LiteralControl it has a property called 
EnableViewState. When a page is built every control that has this property 
enabled contributes to the view state by serializing its contents
State Bag class is used to manage viewstate.  This class is like a 
dictionary�you may store key/value pairs in it. This is how you store a piece 
of useful data in the view state:
ViewState ["SortOrder"] = "email" Susan Warren has kindly put together this 
decision chart of view state vs. session:
  Session State View State
Holds server resources? Yes No
Times out? Yes � after 20 minutes (default) No
Stores any .NET type? Yes No, limited support for: strings, integers, Booleans, 
arrays, ArrayList, hashtable, custom TypeConverters
Increases "HTML payload"? No Yes By default view state is enabled (as of 
ASP.NET 1.1)
machine.config reveals this much:
<pages enableViewState="true" enableViewStateMac="true" ... />
The nature of machine.config prescribes general settings for all applications. 
In other words since view state is enabled on the machine level it is enabled 
on the application, page and control level. Thus each server control has view 
state enabled by default
To disable view state of an individual control set its EnableViewState to false:
<asp:Label id=Label1 runat="server" EnableViewState="false" />
As a rule of thumb if a control does not contain any dynamic data, or its value 
is hardcoded or assigned on every page request and you're not handling its 
events you can disable the control's view state. To disable view state on an 
entire page by modifying the Page directive:
<%@ Page ... EnableViewState="false" %> To disable view state on the whole web 
application by adding the following line to your web.config:
<pages enableViewState="false" />   
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to