Cannot store arraylist in session

Discussion in 'ASP .Net' started by ricardo.sobral.santos@googlemail.com, Mar 29, 2007.

  1. Guest

    Hi there,

    I cannot store an arraylist in a session. I have read some posts and
    still found no solution. I am sure it might be something simple, but
    since I have been around it for quite sometime I ask for your advice.

    Here is my page load.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
    Dim users As New ArrayList
    users = User_.ArrayOfUsers ' This gets an array of
    users. (User_ is just an object)
    Session.Add("users", users)
    Session.Add("i", 0)

    i = 0
    details =
    User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users.Item(i))
    Image.ImageUrl = details(1).ToString
    lblLastChecked.Text = details(3).ToString
    details.Clear()
    users.Clear()
    Else
    i = CType(Session("i"), Integer)
    Dim users_tmp As New ArrayList
    users_tmp = CType(Session("users"), ArrayList) ' Why is
    this empty?!?! I cannot understand...

    detailsAfterRating =
    User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.Item(i))
    details =
    User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.Item((i
    + 1)))

    Image.ImageUrl = details(1).ToString
    lblLastChecked.Text = details(2).ToString

    RatedImage.ImageUrl = detailsAfterRating(2).ToString
    lblRating.Text = detailsAfterRating(5).ToString
    lblPastRate.Text = yourRating.ToString
    i = (i + 1)
    Session.Add("i", i)
    details.Clear()
    detailsAfterRating.Clear()
    End If
    End Sub
    , Mar 29, 2007
    #1
    1. Advertising

  2. Hans Kesting Guest

    See inline

    > Hi there,
    >
    > I cannot store an arraylist in a session. I have read some posts and
    > still found no solution. I am sure it might be something simple, but
    > since I have been around it for quite sometime I ask for your advice.
    >
    > Here is my page load.
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > If Not Page.IsPostBack Then
    > Dim users As New ArrayList
    > users = User_.ArrayOfUsers ' This gets an array of
    > users. (User_ is just an object)
    > Session.Add("users", users)


    Here you store a *reference* to the arraylist, not the arraylist itself

    > Session.Add("i", 0)
    > i = 0
    > details =
    > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users.Item
    > (i))
    > Image.ImageUrl = details(1).ToString
    > lblLastChecked.Text = details(3).ToString
    > details.Clear()
    > users.Clear()


    And here you erase the 'users' list, which also erases that list in session,
    as that is exactly the same list!

    > Else
    > i = CType(Session("i"), Integer)
    > Dim users_tmp As New ArrayList


    Minor note: you don't need "new" here: you don't want to create a new instance
    here as that will be overwritten in the next line

    > users_tmp = CType(Session("users"), ArrayList) ' Why is
    > this empty?!?! I cannot understand...
    > detailsAfterRating =
    > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.
    > Item(i))
    > details =
    > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.
    > Item((i
    > + 1)))
    >
    > Image.ImageUrl = details(1).ToString
    > lblLastChecked.Text = details(2).ToString
    > RatedImage.ImageUrl = detailsAfterRating(2).ToString
    > lblRating.Text = detailsAfterRating(5).ToString
    > lblPastRate.Text = yourRating.ToString
    > i = (i + 1)
    > Session.Add("i", i)
    > details.Clear()
    > detailsAfterRating.Clear()
    > End If
    > End Su
    Hans Kesting, Mar 29, 2007
    #2
    1. Advertising

  3. Guest

    On 29 Mar, 08:46, Hans Kesting <> wrote:
    > See inline
    >
    >
    >
    >
    >
    > > Hi there,

    >
    > > Icannotstoreanarraylistin asession. I have read some posts and
    > > still found no solution. I am sure it might be something simple, but
    > > since I have been around it for quite sometime I ask for your advice.

    >
    > > Here is my page load.

    >
    > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Me.Load

    >
    > > If Not Page.IsPostBack Then
    > > Dim users As NewArrayList
    > > users = User_.ArrayOfUsers ' This gets an array of
    > > users. (User_ is just an object)
    > >Session.Add("users", users)

    >
    > Here youstorea *reference* to thearraylist, not thearraylistitself
    >
    > >Session.Add("i", 0)
    > > i = 0
    > > details =
    > > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users.Item
    > > (i))
    > > Image.ImageUrl = details(1).ToString
    > > lblLastChecked.Text = details(3).ToString
    > > details.Clear()
    > > users.Clear()

    >
    > And here you erase the 'users' list, which also erases that list insession,
    > as that is exactly the same list!
    >
    > > Else
    > > i = CType(Session("i"), Integer)
    > > Dim users_tmp As NewArrayList

    >
    > Minor note: you don't need "new" here: you don't want to create a new instance
    > here as that will be overwritten in the next line
    >
    >
    >
    > > users_tmp = CType(Session("users"),ArrayList) ' Why is
    > > this empty?!?! Icannotunderstand...
    > > detailsAfterRating =
    > > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.
    > > Item(i))
    > > details =
    > > User_.UserID_Image_Thumbnail_LastCheck_Rating_NumberOfVotes(users_tmp.
    > > Item((i
    > > + 1)))

    >
    > > Image.ImageUrl = details(1).ToString
    > > lblLastChecked.Text = details(2).ToString
    > > RatedImage.ImageUrl = detailsAfterRating(2).ToString
    > > lblRating.Text = detailsAfterRating(5).ToString
    > > lblPastRate.Text = yourRating.ToString
    > > i = (i + 1)
    > >Session.Add("i", i)
    > > details.Clear()
    > > detailsAfterRating.Clear()
    > > End If
    > > End Sub- Hide quoted text -

    >
    > - Show quoted text -- Hide quoted text -
    >
    > - Show quoted text -


    Tks! That solved some issues. Still how can I then store the values
    itself and not the reference?
    Sorry for this, but I am quite newbie at asp.net.

    Thanks.
    , Mar 29, 2007
    #3
  4. Aidy Guest


    > Tks! That solved some issues. Still how can I then store the values
    > itself and not the reference?


    You can't. Just delete the users.Clear line from your code.
    Aidy, Mar 29, 2007
    #4
    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. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,726
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,330
    Kaidi
    Jan 3, 2004
  3. pvdg42
    Replies:
    1
    Views:
    366
    bruce barker
    Mar 29, 2007
  4. xz
    Replies:
    16
    Views:
    2,342
  5. Philipp
    Replies:
    6
    Views:
    898
    Arne Vajhøj
    May 28, 2008
Loading...

Share This Page