ViewState storage

Discussion in 'Site Programming, Development and Design' started by cashokay, Jan 25, 2011.

  1. I have a large TreeView on my page and consequently a large viewstate. I am using SavePageStateToPersistenceMedium to save to Session and/or Cache to improve server to client response. Works great on development computer, but seems to have no effect on Winhost.

    Looking for ideas or thoughts on why??
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    This is hard to say since you brought up viewstate, sessions, and cache. All three are separate from each other although can be used to work hand in hand. Do you have a URL we can look at to see how the treeview is performing? That might help us shed some light on the matter.
     
  3. www.craigs-lister.com/search.aspx

    Here is code snippet - Session version. The commented cache code has same result.

    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);
    Session["viewstate"] = str;
    ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", str);
    ClientScript.RegisterHiddenField("__VIEWSTATE", String.Empty);
    }

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

    Ray

    I'm not seeing any latency or problems on the TreeView I do see a Request Timed Out error when I perform some searches. Is that the problem you are having? If not what are the instructions where I can replicate the problem you are seeing?
     
  5. If you looked at html (view source) for the search.aspx page you will see a very large VIEWSTATE hidden field. The code in earlier post can be used to process the view state funtion on the server vs. client and greatly reduce the data transferred on each page post. The large VIEWSTATE hidden field is due to the 2 large TreeView controls.

    Re: Timeout. I suspect that happened when a large matrix of Locations and Categories was 'searched'. I may have to restrict that, but I'm not concerned right now about that.

    Thanks for your help.
     
  6. Ray

    Ray

    Now I'm a bit confused. What exactly are you trying to do? Are you trying to save your viewstate into some session object or cache? Can you elaborate a little more on what you are trying to accomplish? I thought you were having some some latency or web performance issue.
     
  7. Yes, I am trying to save/load viewstate in/from a session variable using the methods I posted earlier. I'm doing this to reduce the amount of data being transferred between client and server.

    If I look at the page html on development system, here is an excerpt:


    <body>

    <form method="post" action="Search.aspx" id="Form1">

    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />

    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />


    <div class="aspNetHidden">

    Compare to Winhost:

    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE3MTYxNzU4MDkPZBYCZg9kFgJmD2QWAgIDD2QWAgIJD2QWBAIBD2QWAgIDD2QWAmYPZBYCAgEPPCsACQIADxYGHglMYXN0SW5kZXgC4gQeDFNlbGVjdGVkTm9kZWQeDU5ldmVyRXhwYW5kZWRkZAgUKwADBQsyOjAsMDowLDA6MRQrAAIWCB4EVGV4dAUDVVNBHgxTaG93Q2hlY2tCb3hnHgtOYXZpZ2F0ZVVybAUlaHR0cDovL3d3dy5jcmFpZ3NsaXN0Lm9yZy9hYm91dC9zaXRlcx4IRXhwYW5kZWRoFCsANgX+ATA6MCwwOjEsMDoyLDA6MywwOjQsMDo1LDA6NiwwOjcsMDo4LDA6OSwwOjEwLDA6MTE etc....

    Is there something that needs to be set on Winhost server to do this?
     
    Last edited by a moderator: Oct 14, 2015

Share This Page