ViewState is HUGE

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
 
A

Alex D.

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.
 
E

Eliyahu Goldin

Lars,

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

Eliyahu
 
M

Marcel van den Hof

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,965
Members
46,294
Latest member
HollieYork

Latest Threads

Top