ViewState Aspect Reduction Strategies in asp.net

I am using the 'n' number of server controls on my page. Now I'm doing performance tuning, and I noticed that my ViewState too large and it makes my page slow.

I know that ViewState size can be compressed by Gzip. Any other suggestions for abbreviation ViewState in asp.net. I do not want to do in IIS because my web application is hosted on a shared server.

+4
source share
6 answers

Assuming that the size of the viewstate is the main reason for β€œslowness,” I would suggest that you develop it from a more holistic approach.

You have the "n" number of server controls, do you need all the "n" numbers to control the server, not just HTML?

Say that you really need all the "n" of them, should they all have view mode turned on?

Here is one good article (if you haven’t read it yet) that gives more information: VIEWSTATE minimization

+8
source

EnableViewState = false; should become your friend.

Assuming you are currently using viewstate ONLY where you need it, you can do the following:

  • Switch Labels to Literals , especially if you use them in templates. Shortcuts take up much more viewing space.
  • Try to reduce the number of postbacks. Fewer postbacks will force you to use fewer views since you do not need to reload the entire page. For example, use AJAX calls and write data using client-side processing.
  • Use session or caching to store large amounts of data for networks and data arrays. With each reboot, just fill it yourself.
+5
source

Viewstates should only be used when you need to remember the state of a page between postbacks. It was used to prevent additional access to the database. So, if this is not required for your control, use EnableViewState = False . If nothing on your page needs a viewstate, you can disable the widgets for this page by adding EnableViewState = False to the Page tag.

If your server can afford it, you can transfer data to Sessions . Do this if necessary to ensure security (the viewstate should not contain sensitive data), or if your view contains a large amount of data. Be careful, because Sessions is stored in server memory by default. Thus, you do not want to use this too much with big data if you expect many concurrent users. However, you can change the storage location of the session (i.e., another server).

+2
source

The first thing you need to do is turn off the viewstate wherever you need it. Examine the controls and determine which ones are absolutely necessary to enable viewing mode.

0
source

That is the question that I had. I had to extend the HiddenFieldPageStatePersister and save the view in the database. I wrote an entire article to help you.

http://ashishnangla.com/2011/07/21/reducing-size-of-viewstate-in-asp-net-webforms-by-writing-a-custom-viewstate-provider-pagestatepersister-part-12/

0
source

Add the following code to the page that generates large viewstate values. Alternatively, this can be added to the home page to eliminate the need to add to each page. The code below allows you to save storage in a session.

  protected override PageStatePersister PageStatePersister { get { return new SessionPageStatePersister(this); } } 
0
source

All Articles