468,110 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

ASP class-session variable

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

%>
Jul 19 '05 #1
8 6701
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

%>

Jul 19 '05 #2
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.

Jul 19 '05 #3
Hiya,

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

Thanks!!
"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.


Jul 19 '05 #4
Did you try Google?
http://www.google.ca/search?q=asp+st...-8&hl=en&meta=

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

"Tammy B." <Tb@stinkylips.com> wrote in message
news:Os**************@TK2MSFTNGP12.phx.gbl...
Hiya,

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

Thanks!!
"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.



Jul 19 '05 #5
Ray, what's the SQL Server help you need/want?
"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.


Jul 19 '05 #6
thanks! I will put my hair back in my head now.


"Tom B" <sh*****@hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Did you try Google?
http://www.google.ca/search?q=asp+st...-8&hl=en&meta=
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=195

"Tammy B." <Tb@stinkylips.com> wrote in message
news:Os**************@TK2MSFTNGP12.phx.gbl...
Hiya,

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

Thanks!!
"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
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." <Tb@stinkylips.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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.
>



Jul 19 '05 #7
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" <sh*****@hotmail.com> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
Ray, what's the SQL Server help you need/want?

Jul 19 '05 #8
I see
"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:eg**************@TK2MSFTNGP11.phx.gbl...
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" <sh*****@hotmail.com> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
Ray, what's the SQL Server help you need/want?


Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fernando Rodriguez | last post: by
5 posts views Thread by Andy | last post: by
3 posts views Thread by Hamilton Woods | last post: by
reply views Thread by emin.shopper | last post: by
2 posts views Thread by Cari Elf | last post: by
19 posts views Thread by jan.loucka | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.