Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Cannot store arraylist in session

Reply
Thread Tools

Cannot store arraylist in session

 
 
ricardo.sobral.santos@googlemail.com
Guest
Posts: n/a
 
      03-29-2007
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_Numb erOfVotes(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_Numb erOfVotes(users_tmp.Item(i))
details =
User_.UserID_Image_Thumbnail_LastCheck_Rating_Numb erOfVotes(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

 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      03-29-2007
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_Numb erOfVotes(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_Numb erOfVotes(users_tmp.
> Item(i))
> details =
> User_.UserID_Image_Thumbnail_LastCheck_Rating_Numb erOfVotes(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



 
Reply With Quote
 
 
 
 
ricardo.sobral.santos@googlemail.com
Guest
Posts: n/a
 
      03-29-2007
On 29 Mar, 08:46, Hans Kesting <(E-Mail Removed)> 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_Numb erOfVotes(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_Numb erOfVotes(users_tmp.
> > Item(i))
> > details =
> > User_.UserID_Image_Thumbnail_LastCheck_Rating_Numb erOfVotes(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.

 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      03-29-2007

> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the clone() method of ArrayList<> make a copy of the objects in the ArrayList? xz Java 16 08-04-2007 10:33 PM
Re: Cannot store arraylist in session - Please help pvdg42 ASP .Net 1 03-29-2007 03:27 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
writeObject with ArrayList of ArrayList? Kaidi Java 4 01-03-2004 08:16 PM
Iterate through ArrayList using an another ArrayList Saravanan Rathinavelu ASP .Net 3 08-19-2003 07:03 AM



Advertisments