Session Variable storing IList Collection

Last post 05-14-2007 12:38 PM by boyd5. 3 replies.

Sort Posts:

  • Session Variable storing IList Collection

    05-11-2007, 4:45 PM
    • Member
      point Member
    • cshong29
    • Member since 05-11-2007, 8:41 PM
    • Posts 1
    I am completely at a lost here.  I feel like that I am missing something, but not too sure what that is right now.

    I have a class that implements IList that I am trying to store in a session variable.  The session variable seems to be populated before I do a page post back.  After I do a page post back the session variable is no longer populated.

    How do I keep an IList Collection populated in a session variable through a page post back?  Am I missing something?

    Thanks,
    Charles
  • Re: Session Variable storing IList Collection

    05-11-2007, 4:57 PM
    Answer
    • Contributor
      3,086 point Contributor
    • Girijesh
    • Member since 10-27-2005, 12:04 PM
    • India
    • Posts 652
    If you want any variable to be maintained, user ViewState. Keep the IList collection on ViewState.
  • Re: Session Variable storing IList Collection

    05-12-2007, 3:32 PM
    Answer
    • Member
      66 point Member
    • damferit
    • Member since 03-16-2007, 1:58 PM
    • Turkey
    • Posts 8

    If you do not want your object to be populated before a post back you must ensure that the request is
    infact a POST before you save your object to session

    I guess you have some code blocks as following;

    Sessin["myObject"] = myObject;

    You need to check the request method before saving your object as following

    if (Request.HttpMethod=="POST")
        Sessin["myObject"] = myObject;
     P.S. You should not store too much data in session variables.
  • Re: Session Variable storing IList Collection

    05-14-2007, 12:38 PM
    • Participant
      1,033 point Participant
    • boyd5
    • Member since 07-25-2002, 6:48 AM
    • Tranquility, NJ
    • Posts 226

    DO NOT STORE COLLECTIONS IN THE VIEWSTATE.

     That's insanity.  Your page could take a month to load.

    -Adam Boyd


    Systems Architect
Page 1 of 1 (4 items)