tbiro.com

Forums 
   HackPerfCounter
   RADPass
   SHEdit
   Toys
 
   Contact me
   My PGP Key
 

Disable the ViewState, you won't regret it


The ViewState is turned on by default for all ASP.NET applications. Any data in ViewState automatically makes a round trip to the browser. This increases the page size and it affects the overall performance and user experience.

If your application contains complex controls such as DataGrids the size of the data posted back is especially large. Several big controls can have a significant impact on response times so it is important to disable the ViewState either for the entire site or for specific controls.

I recommend disabling the ViewState at the highest possible level and only re-enable it at lower levels as needed.

Here is how to manipulate the ViewState setting at various levels:

Edit the ViewState at the control level:
<asp:TextBox id="title" runat="server" EnableViewState="false" />
Edit the ViewState at the page level:
<%@ Page EnableViewState="false" %>

Edit the ViewState at the site level by editing the web.config file ar at the computer level by editing the machine.config file:

<Pages enableViewState="false"/>

Experiment with these settings and examine the generated page sources to see the difference in the ViewState size.

Comments: tb@tbiro.com






View mys profile on LinkedIn