Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Cannot store arraylist in session (http://www.velocityreviews.com/forums/t494805-cannot-store-arraylist-in-session.html)

ricardo.sobral.santos@googlemail.com 03-29-2007 07:04 AM

Cannot store arraylist in session
 
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


Hans Kesting 03-29-2007 07:46 AM

Re: Cannot store arraylist in session
 
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




ricardo.sobral.santos@googlemail.com 03-29-2007 08:02 AM

Re: Cannot store arraylist in session
 
On 29 Mar, 08:46, Hans Kesting <news.2.han...@spamgourmet.com> 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.


Aidy 03-29-2007 08:52 AM

Re: Cannot store arraylist in session
 

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




All times are GMT. The time now is 12:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57