Trimming down that ViewState

I’m developing an ASP.Net site for a client that is very concerned about bandwidth. My first objective is to reduce the size of the hidden veiwstate data returned in the form.

The worst culprits seem to be the data display controls, especially the DataGrid. I found that for displaying small amounts of data in a table (20 rows by 5 columns) the page with a DataGrid returned over twice as much view state data (5,716 bytes vs 2,512 bytes) as one using a Repeater to render the table.

Worse yet, once I started returning larger amounts of data, even the Repeater was generating a heafty amount of veiw state data. Since these pages are essentially run once search result pages, I’ve added the following to the Page directive

EnableViewState=”false”

ASP.Net still returns view state data for the page, but only a small amount. To completely remove it from the page, you have to remove all runat=”server” tags.

The following article also shows how to trim the ViewState data on a control by control basis:

http://www.codeproject.com/aspnet/hmvsiooc.asp