ASP.NET Cafe
Tips and Tricks

ViewState on server

Monday, 10 December 2007 07:54 by Dmitriy

There are a lot of things inside your aspx page... And viewstate is there. What if everything ok, and viewstate size not very big. But what if viewstate size too big?
First of all, maybe you are using viewstate in some controls that don't need it. But, what if we still need viewstate, but page loading slowly? Not a problem, people have good internet speed! But the problem with Viewstate and AJAX pages. Ajax enabled page post it every partial postback... and more traffic, more timeout between updates. Ugly.

Sometimes ago, I've searched for a solution. My friends told me - jump to JSP.
But I still love ASP and specially with AJAX. The solution is very-very simple:

On the page that has a lot of partial postbacks... better to use SessionPageStatePersister class.  Just add following lines to your code:

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

And that's all. Not all pages, just this one uses ViewState on Server. There are possibility to store ViewState anywhere... in cache, session, sql database, hidden fields, xml files. But this thing is EASY, and makes your AJAX pages fly! 

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , , ,
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Preview

December 4. 2008 12:26