Results 1 to 5 of 5

Thread: How to get values from session objects?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    How to get values from session objects?

    I ahve a collection object saved in the session
    I have also declared a new collection object

    When I do the following(written from memory )

    dim newcoll as new collection
    newcoll = Cast(Session("Collection"), Collection)


    I get only a reference to the session collection.. so when I am editing newcoll I am manipulating the sessions collection...
    How can I get the value?

    kind regarrds
    Henrik

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    isn't this ASP.NET?

    when i store a dataset as a session object I don't cast it when getting the value back and it seems to work ok.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    yes it's asp.net...

    The problem we are having is that when we perform the cast, a reference to the object in session. SO when we alter the values in the collection... the session collection is altered... not what we wanted.

    I know byref is default in .net...


    kinds regards
    Henrik

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you don't want to alter the session collection then why are you using it? I'm confused.

    VB Code:
    1. dim newcoll as new collection
    2. 'this assigns the collection object created in the last line to
    3. 'the session collection instead of the one created
    4. 'in fact using New here does nothing since you assign it
    5. 'to another collection in the next line
    6. newcoll = DirectCast(Session("Collection"), Collection)

    Are you trying to work with a copy of the collection? If so then you'll need to write a routine that actually copies the properties of the items to new items and adds them to the new collection. This all happens because the collection object is a reference type not a value type.
    Last edited by Edneeis; Feb 2nd, 2004 at 02:31 AM.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Actually Im asking for a friend.. he asked me and I didn't have a perfect answer to him, so I decided to ask the pros here... I was 99 % sure it was a reference issue but needed to be sure... thanks for the answer.. I have no clue why he want to do it like this

    kind regards
    Henrik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width