----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: mygoodwill770521 Message 1 in Discussion Improving page performance.<o:p></o:p> <o:p></o:p> 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.<o:p></o:p> <o:p></o:p> 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.<o:p></o:p> <o:p></o:p> 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.<o:p></o:p> <o:p></o:p> 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<o:p></o:p> <o:p></o:p> 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.<o:p></o:p> If you view the source of an ASP.NET web form you will see something like this:<o:p></o:p><input type="hidden" name="__VIEWSTATE" <o:p></o:p> value="CEbzzzEnmmz+Bc8IDFlnpgCLJ/HB00...><o:p></o:p> 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<o:p></o:p> 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:<o:p></o:p>ViewState ["SortOrder"] = "email"<o:p></o:p> <o:p></o:p>Susan Warren has kindly put together this decision chart of view state vs. session:<o:p></o:p> <o:p></o:p> Session State<o:p></o:p> View State<o:p></o:p> Holds server resources?<o:p></o:p> Yes<o:p></o:p> No<o:p></o:p> Times out?<o:p></o:p> Yes � after 20 minutes (default)<o:p></o:p> No<o:p></o:p> Stores any .NET type?<o:p></o:p> Yes<o:p></o:p> No, limited support for: strings, integers, Booleans, arrays, ArrayList, hashtable, custom TypeConverters<o:p></o:p> Increases "HTML payload"?<o:p></o:p> No<o:p></o:p> Yes<o:p></o:p> <o:p></o:p> By default view state is enabled (as of ASP.NET 1.1)<o:p></o:p> machine.config reveals this much:<o:p></o:p><pages enableViewState="true" enableViewStateMac="true" ... /><o:p></o:p> 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<o:p></o:p> To disable view state of an individual control set its EnableViewState to false:<o:p></o:p><asp:Label id=Label1 runat="server" EnableViewState="false" /><o:p></o:p> 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.<o:p></o:p> <o:p></o:p> To disable view state on an entire page by modifying the Page directive:<o:p></o:p><%@ Page ... EnableViewState="false" %><o:p></o:p> <o:p></o:p> To disable view state on the whole web application by adding the following line to your web.config:<o:p></o:p><pages enableViewState="false" /><o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> ----------------------------------------------------------- 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]
