ViewState is HUGE

  • Thread starter Thread starter Lars Grøtteland
  • Start date Start date
L

Lars Grøtteland

Hello!

My ViewState is huge. I have a couple two comboboxes, three edit boxes with
one button each, and a dataGrid.
I'm showing 200 items in the grid, and when the page loads, the viewState is
61 pages pasted into Word. - That's over 3/4 of the aspx page.

Any help how to size down this ViewState would be appreciated.

- Lars
 
just disable ViewState for the whole DataGrid and bind it every time the
page is loaded. if you need to post back some fields from your datagrid then
just disable the viewstate for the other fields, in order to do that you may
need to use template fields for the ones you one to disable postback.
 
Lars,

If you re-populate the datagrid on every postback, you can disable it's
ViewState. It will save a lot.

Eliyahu
 
Hi Lars,

If you would like to use datagrid functionality like paging and
sorting then I would not recommend to disable the viewstate on the
datagrid itself.

My recommended approach would be:
1: Rebind to the grid on every postback.
2: Disable the viewstate for each row of type ListItemType.Item.

So for example in the DataGrid1_ItemCreated event you could add the
following line of code:

if (e.Item.ItemType == ListItemType.Item)
e.Item.EnableViewState = false;

That little line of magic there will shorten the viewstate
considerably. But you will need to rebind on every postback.

Let me know if this works out for you.

Regards,

Marcel van den Hof
 
Back
Top