My ViewState is huge! What can I do?

G

Gummy

Hello,

I have an ASPX page on which I place a UserControl 15 times (they only need
to be static controls on the page). This UserControl is a set of two
listboxes with radiobuttons above the listbox (to select between viewing a
code or description in the listbox). There are also left and right arrows
that move the selected items between the listboxes.

In my Page_Load I assign each UserControl the appropriate DataTable and this
assignment only happens when it is not a PostBack. So I know (pretty sure)
that I am not reloading all that data each time.

Each listbox (on the left) is loaded with data from stored procedures. When
I click the right arrow to move a selection from the left to the right
listbox it causes a postback (as expected). The problem is that I only need
to do a postback for the UserControl where I made the change (if that makes
any sense). The entire page doesn't need to be reloaded.

When I click an arrow in a UserControl, the bottom of IE says, "Opening
http:/localhost/..." This occurs even before it gets to the Page_Load.

Is there a way I can have a postback only on the UserControl I am clicking
on? I have ViewState on and when I look at the ViewSource, the ViewState is
just huge! The problem is some of these listboxes, in the UserControls, have
a large amount of data and I don't think it makes much sense to repopulate
them on each postback, yet I am forced to have this huge ViewState that is
really slowing things down.

Any help is greatly appreciated.
 
G

Guest

Gummy,

1) You should be able to turn on ViewState for individual controls (and on
or off for the Page).
2) If the data that's loaded for each control doesn't change, you should
consider storing it in Cache so that you do not need to keep making round
trips to the database just to get the same data back again.
Peter
 
G

Gummy

Peter,

I really appreciate the information.

If I understand this correctly, on Postback the control for which I shut off
ViewState will not repopulate, is that correct?

If I use Cache, what part of the application takes the hit with all that
data?
When using Cache, do I use it the same way as ViewState (maybe just a search
and replace in my code) and .NET will take care of the rest?
Do I need to turn on/off Cache for just the controls whose data is changing?

Thank you.
 
D

Damien

Gummy said:
Hello,

I have an ASPX page on which I place a UserControl 15 times (they only need
to be static controls on the page). This UserControl is a set of two
listboxes with radiobuttons above the listbox (to select between viewing a
code or description in the listbox). There are also left and right arrows
that move the selected items between the listboxes.

In my Page_Load I assign each UserControl the appropriate DataTable and this
assignment only happens when it is not a PostBack. So I know (pretty sure)
that I am not reloading all that data each time.

Each listbox (on the left) is loaded with data from stored procedures. When
I click the right arrow to move a selection from the left to the right
listbox it causes a postback (as expected). The problem is that I only need
to do a postback for the UserControl where I made the change (if that makes
any sense). The entire page doesn't need to be reloaded.

When I click an arrow in a UserControl, the bottom of IE says, "Opening
http:/localhost/..." This occurs even before it gets to the Page_Load.

Is there a way I can have a postback only on the UserControl I am clicking
on? I have ViewState on and when I look at the ViewSource, the ViewState is
just huge! The problem is some of these listboxes, in the UserControls, have
a large amount of data and I don't think it makes much sense to repopulate
them on each postback, yet I am forced to have this huge ViewState that is
really slowing things down.

Any help is greatly appreciated.

Hi Gummy,

To put things simply: No.

Unless you're using frames (which just about everyone hates these days,
so I'll assume you're not), whenever you cause a postback, the entire
page has to be regenerated. This is because, as far as your browser is
concerned, it is navigating from one page to another. It has to be
supplied with all of the information it needs to render this "new"
page. That includes all of the data in all of the controls on the page.

Now, if you use viewstate, all of the information needed to repopulate
the controls is stored there, and is used to reconstruct the data
within those controls. If you disable viewstate for the controls, then
they will not know what they should contain (unless you reload them
from the database). It this simple: new page needs all of the data from
the old page. You either put in in the viewstate or you reload it from
the database. Either way will have performance hits.

Could you convert your user controls so that, if javascript is
available, they do most of their work client side, and so you only post
back when the whole page needs it? (Or possibly, if every movement
needs to be known about server side, use AJAX rather than causing a
postback)

Damien
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top