View State and Server caching

Discussion in 'ASP .Net' started by abcd, Aug 8, 2008.

  1. abcd

    abcd Guest

    My application is using ASP.NET 3.0 and My ASPX pages contain Master page,
    and content page. The content page (.aspx) has various User controls (ascx).
    My page view state is significantly large and I am looking for some smart way
    to rfeduce the page size. So I indentified to manipulate ViewState. When page
    is posted I will park the ViewState on Server and viewState will not move
    back and forth. I am doing code as below in Page level by overrriding below
    methods.

    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
    string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
    DateTime.Now.Ticks.ToString();
    Cache.Add(str, viewState, null,
    DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
    CacheItemPriority.Default, null);
    RegisterHiddenField("__VIEWSTATE_KEY", str);
    RegisterHiddenField("__VIEWSTATE", "");
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
    string str = Request.Form["__VIEWSTATE_KEY"];
    if (!str.StartsWith("VIEWSTATE_"))
    {
    throw new Exception("Invalid viewstate key:" + str);
    }
    return Cache[str];
    }

    This is not working good for me. My pages get invalid viewState errors. I am
    using Workflows too. Any idea how these methods can be better tuned when a
    page contains multiple user controls.

    Thanks
     
    abcd, Aug 8, 2008
    #1
    1. Advertising

  2. So how is viewstate going to get to the client if you park it on the server?
    It must move there eventually right? I suggest you look at reducing the size
    of viewstate first but turning it off controls and pages that don't require
    it. Remember, items like textbox don't need it. There's also control state
    which is more efficient and tends to be lighter. However, I think you are
    heading in the right direction for optimization.

    --

    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    Download OWC Black Book, 2nd Edition
    Exclusively on www.lulu.com/owc $15.00
    Need a free copy of VSTS 2008 w/ MSDN Premium?
    http://msmvps.com/blogs/alvin/Default.aspx
    -------------------------------------------------------


    "abcd" <> wrote in message
    news:...
    > My application is using ASP.NET 3.0 and My ASPX pages contain Master page,
    > and content page. The content page (.aspx) has various User controls
    > (ascx).
    > My page view state is significantly large and I am looking for some smart
    > way
    > to rfeduce the page size. So I indentified to manipulate ViewState. When
    > page
    > is posted I will park the ViewState on Server and viewState will not move
    > back and forth. I am doing code as below in Page level by overrriding
    > below
    > methods.
    >
    > protected override void SavePageStateToPersistenceMedium(object
    > viewState)
    > {
    > string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
    > DateTime.Now.Ticks.ToString();
    > Cache.Add(str, viewState, null,
    > DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
    > CacheItemPriority.Default, null);
    > RegisterHiddenField("__VIEWSTATE_KEY", str);
    > RegisterHiddenField("__VIEWSTATE", "");
    > }
    >
    > protected override object LoadPageStateFromPersistenceMedium()
    > {
    > string str = Request.Form["__VIEWSTATE_KEY"];
    > if (!str.StartsWith("VIEWSTATE_"))
    > {
    > throw new Exception("Invalid viewstate key:" + str);
    > }
    > return Cache[str];
    > }
    >
    > This is not working good for me. My pages get invalid viewState errors. I
    > am
    > using Workflows too. Any idea how these methods can be better tuned when a
    > page contains multiple user controls.
    >
    > Thanks
     
    Alvin Bruney [ASP.NET MVP], Aug 10, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    462
  2. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    843
    Troy Simpson
    Jan 19, 2004
  3. Replies:
    6
    Views:
    486
    John Timney \( MVP \)
    Nov 30, 2005
  4. JimLad
    Replies:
    3
    Views:
    948
    JimLad
    Jan 21, 2010
  5. Parthiv Joshi
    Replies:
    1
    Views:
    809
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page