Using View State


The use of view state by ASP.NET allows us to easily build sophisticated Web applications that have state information carried between requests while using the stateless HTTP protocol. As with the session state feature, using view state has a price. The state information is stored in a hidden field of the form and posted back to the server with the form. The view state information is then parsed and the data restored to the controls. The trace information, discussed earlier in this chapter, allows us to see the size of the view state for individual controls. Databound controls in particular can have very large quantities of view state information.

As the size of the view state grows, so does the time it takes to send the data to the client, receive the data back from the browser, and parse the data. Examine the view state requirements for the pages on your site. Consider server caching of datasets and perform the databinding again when view state size becomes large.

For pages that do not rely on view state information, disable the view state altogether by setting the EnableViewState Page directive attribute to false. For pages that take advantage of view state, you can disable it for user controls separately by setting the @Control EnableViewState property or by setting the EnableViewState attribute on individual controls.




Microsoft ASP. NET Coding Strategies with the Microsoft ASP. NET Team
Microsoft ASP.NET Coding Strategies with the Microsoft ASP.NET Team (Pro-Developer)
ISBN: 073561900X
EAN: 2147483647
Year: 2005
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net