ASP class-session variable

Discussion in 'ASP General' started by Tammy B., Jul 21, 2003.

  1. Tammy B.

    Tammy B. Guest

    Hiya - Big puzzler for me. Code Below
    I create a class. I save it to a session variable.
    Then, I retrieve the session variable back into a new local variable.
    I am able to use a method which prints the name "Joey."

    Works great.

    But if I retrieve the same session variable into a local variable from a
    different page, I cannot use the method. It fails.
    Even though the session variable is an object, and the local variable is an
    object!
    Why? How can I get to this class from the second page?

    thanks

    <%
    dim oTest

    set oTest= new clsEmployee
    oTest.EmployeeName="Joey"

    set session("sessionTest")= oTest
    set oTest= nothing

    'This section works fine------------------------------
    'But not from another page!
    dim oNewTest
    set oNewTest = session("sessionTest")
    Response.Write "<br>Is oNewTest an object? " & isObject(oNewTest)
    Response.Write "<Br>"
    Onewtest.PrintEmployeeName
    ---------------------------------------

    Class clsEmployee

    Private m_strEmployeeName

    Public Property Get EmployeeName
    EmployeeName = m_strEmployeeName
    End Property

    Public Property Let EmployeeName (strEmployeeName)
    m_strEmployeeName = strEmployeeName
    End Property


    Sub PrintEmployeeName
    Response.Write EmployeeName
    End Sub

    End Class

    %>
    Tammy B., Jul 21, 2003
    #1
    1. Advertising

  2. Tammy B.

    Chris Barber Guest

    I'm pretty sure you can't save VBScript classes into session variables and
    expect them to be persisted. I think they are still accessible within the
    context of the same ASP page but not when re-loaded to a different page.

    M. Harris has posted about this on numerous occasions?

    Chris.

    "Tammy B." <> wrote in message
    news:%...
    > Hiya - Big puzzler for me. Code Below
    > I create a class. I save it to a session variable.
    > Then, I retrieve the session variable back into a new local variable.
    > I am able to use a method which prints the name "Joey."
    >
    > Works great.
    >
    > But if I retrieve the same session variable into a local variable from a
    > different page, I cannot use the method. It fails.
    > Even though the session variable is an object, and the local variable is

    an
    > object!
    > Why? How can I get to this class from the second page?
    >
    > thanks
    >
    > <%
    > dim oTest
    >
    > set oTest= new clsEmployee
    > oTest.EmployeeName="Joey"
    >
    > set session("sessionTest")= oTest
    > set oTest= nothing
    >
    > 'This section works fine------------------------------
    > 'But not from another page!
    > dim oNewTest
    > set oNewTest = session("sessionTest")
    > Response.Write "<br>Is oNewTest an object? " & isObject(oNewTest)
    > Response.Write "<Br>"
    > Onewtest.PrintEmployeeName
    > ---------------------------------------
    >
    > Class clsEmployee
    >
    > Private m_strEmployeeName
    >
    > Public Property Get EmployeeName
    > EmployeeName = m_strEmployeeName
    > End Property
    >
    > Public Property Let EmployeeName (strEmployeeName)
    > m_strEmployeeName = strEmployeeName
    > End Property
    >
    >
    > Sub PrintEmployeeName
    > Response.Write EmployeeName
    > End Sub
    >
    > End Class
    >
    > %>
    >
    >
    Chris Barber, Jul 21, 2003
    #2
    1. Advertising

  3. Tammy B.

    Ray at Guest

    There really isn't any reason that storing your classes in session variables
    shouldn't work, really, if you have just one application with that stored,
    but I think that you should probably not store classes in session variables.

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Tammy B." <> wrote in message
    news:%...
    > Hiya - Big puzzler for me. Code Below
    > I create a class. I save it to a session variable.
    > Then, I retrieve the session variable back into a new local variable.
    > I am able to use a method which prints the name "Joey."
    >
    > Works great.
    >
    Ray at, Jul 21, 2003
    #3
  4. Tammy B.

    Tammy B. Guest

    Hiya,

    Would someone mind telling me what is wrong with the code, or why the code
    doesn't work?

    Thanks!!


    "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    message news:%...
    > There really isn't any reason that storing your classes in session

    variables
    > shouldn't work, really, if you have just one application with that stored,
    > but I think that you should probably not store classes in session

    variables.
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Tammy B." <> wrote in message
    > news:%...
    > > Hiya - Big puzzler for me. Code Below
    > > I create a class. I save it to a session variable.
    > > Then, I retrieve the session variable back into a new local variable.
    > > I am able to use a method which prints the name "Joey."
    > >
    > > Works great.
    > >

    >
    >
    Tammy B., Jul 21, 2003
    #4
  5. Tammy B.

    Tom B Guest

    Did you try Google?
    http://www.google.ca/search?q=asp store objects in session&ie=UTF-8&oe=UTF-8&hl=en&meta=

    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=195





    "Tammy B." <> wrote in message
    news:...
    > Hiya,
    >
    > Would someone mind telling me what is wrong with the code, or why the code
    > doesn't work?
    >
    > Thanks!!
    >
    >
    > "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    > message news:%...
    > > There really isn't any reason that storing your classes in session

    > variables
    > > shouldn't work, really, if you have just one application with that

    stored,
    > > but I think that you should probably not store classes in session

    > variables.
    > >
    > > Ray at home
    > >
    > > --
    > > Will trade ASP help for SQL Server help
    > >
    > >
    > > "Tammy B." <> wrote in message
    > > news:%...
    > > > Hiya - Big puzzler for me. Code Below
    > > > I create a class. I save it to a session variable.
    > > > Then, I retrieve the session variable back into a new local variable.
    > > > I am able to use a method which prints the name "Joey."
    > > >
    > > > Works great.
    > > >

    > >
    > >

    >
    >
    Tom B, Jul 21, 2003
    #5
  6. Tammy B.

    Tom B Guest

    Ray, what's the SQL Server help you need/want?


    "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    message news:%...
    > There really isn't any reason that storing your classes in session

    variables
    > shouldn't work, really, if you have just one application with that stored,
    > but I think that you should probably not store classes in session

    variables.
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Tammy B." <> wrote in message
    > news:%...
    > > Hiya - Big puzzler for me. Code Below
    > > I create a class. I save it to a session variable.
    > > Then, I retrieve the session variable back into a new local variable.
    > > I am able to use a method which prints the name "Joey."
    > >
    > > Works great.
    > >

    >
    >
    Tom B, Jul 21, 2003
    #6
  7. Tammy B.

    Tammy B. Guest

    thanks! I will put my hair back in my head now.




    "Tom B" <> wrote in message
    news:%23VO0%...
    > Did you try Google?
    >

    http://www.google.ca/search?q=asp store objects in session&ie=UTF-8&oe=UTF-8&hl=en&meta=
    >
    > http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=195
    >
    >
    >
    >
    >
    > "Tammy B." <> wrote in message
    > news:...
    > > Hiya,
    > >
    > > Would someone mind telling me what is wrong with the code, or why the

    code
    > > doesn't work?
    > >
    > > Thanks!!
    > >
    > >
    > > "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    > > message news:%...
    > > > There really isn't any reason that storing your classes in session

    > > variables
    > > > shouldn't work, really, if you have just one application with that

    > stored,
    > > > but I think that you should probably not store classes in session

    > > variables.
    > > >
    > > > Ray at home
    > > >
    > > > --
    > > > Will trade ASP help for SQL Server help
    > > >
    > > >
    > > > "Tammy B." <> wrote in message
    > > > news:%...
    > > > > Hiya - Big puzzler for me. Code Below
    > > > > I create a class. I save it to a session variable.
    > > > > Then, I retrieve the session variable back into a new local

    variable.
    > > > > I am able to use a method which prints the name "Joey."
    > > > >
    > > > > Works great.
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Tammy B., Jul 21, 2003
    #7
  8. Tammy B.

    Ray at Guest

    Oh, nothing specific at the moment. I just put that there so when I ask
    questions in the SQL group, hopefully people will be like, "ah, that guy
    tries to answer questions in the ASP groups, so I'll give him a couple of
    minutes to help him out with the SQL Server questions..." :]

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Tom B" <> wrote in message
    news:...
    > Ray, what's the SQL Server help you need/want?
    >
    >
    Ray at, Jul 22, 2003
    #8
  9. Tammy B.

    Tom B Guest

    I see
    "Ray at <%=sLocation%>" <7yasdf.com> wrote in
    message news:...
    > Oh, nothing specific at the moment. I just put that there so when I ask
    > questions in the SQL group, hopefully people will be like, "ah, that guy
    > tries to answer questions in the ASP groups, so I'll give him a couple of
    > minutes to help him out with the SQL Server questions..." :]
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Tom B" <> wrote in message
    > news:...
    > > Ray, what's the SQL Server help you need/want?
    > >
    > >

    >
    >
    Tom B, Jul 22, 2003
    #9
    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. Jeff Smythe
    Replies:
    3
    Views:
    1,241
    Jeff Smythe
    Jan 2, 2004
  2. E11
    Replies:
    1
    Views:
    4,755
    Thomas Weidenfeller
    Oct 12, 2005
  3. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,275
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  4. chowchho
    Replies:
    7
    Views:
    631
    Patrice
    Mar 28, 2008
  5. Jazzis
    Replies:
    2
    Views:
    245
    Jazzis
    Sep 23, 2003
Loading...

Share This Page