ASP class-session variable

T

Tammy B.

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

%>
 
C

Chris Barber

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

Ray at

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
 
T

Tammy B.

Hiya,

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

Thanks!!
 
T

Tom B

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


Ray at said:
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
 
R

Ray at

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
 
T

Tom B

I see
Ray at said:
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 said:
Ray, what's the SQL Server help you need/want?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top