Object in Session cannot be accessed

L

Lichunlin

Dear all,

Sorry for cross posting.

I have one page, create an object and save it in session scope, and then redirect to another page.In the new page, the object existed in session object, but can not access its property. The code of page one is :
<%
Class SiteInfo
dim SiteID, SiteName
end class

dim site
set site = new SiteInfo
site.SiteID = "01"
site.SiteName = "Microsoft"
set session("formdata") = site

response.redirect "edit.asp"
%>

the code in edit.asp:
<%
if isObject(session("formdata") then
response.write session("formdata").SiteID
end if
%>

the error occured at line "response.write" :
object can not support the property or method: SiteID

Could you please help me to check why this happen?
Appreciate for any advice.
Best Regards
lichunlin
China
 
A

Aaron [SQL Server MVP]

I have one page, create an object and save it in session scope,

WHY DOES THIS HAVE TO BE AN OBJECT?????

Just use an array, it will make your life much simpler.
 
L

Lichunlin

Dear Aaron,

Thanks for your response.
I would like to create it as an object, because I think the object would be more encapsulated when I use the object more and more times.

Thanks & regards
lichunlin
 
P

Patrice

Does it work when in the same page ?

I would try also to get the object from the session before using it (I
suspect a confusion between the objet that is returned by the session
collection and the object that is stored at this position).

Patrice

--

Lichunlin said:
Dear all,

Sorry for cross posting.

I have one page, create an object and save it in session scope, and then
redirect to another page.In the new page, the object existed in session
object, but can not access its property. The code of page one is :
 
A

Aaron [SQL Server MVP]

I would like to create it as an object, because I think the object would
be more encapsulated when I use the object more and more times.

So, it is more important that it is "more encapsulated", or that it
functions???

Also, are you aware of the dangers of placing (even simple) objects in the
session/application scope? http://www.aspfaq.com/2053
 
L

Larry Bud

Lichunlin said:
Dear all,

Sorry for cross posting.

I have one page, create an object and save it in session scope, and then redirect to another page.In the new page, the object existed in session object, but can not access its property. The code of page one is :
<%
Class SiteInfo
dim SiteID, SiteName
end class

dim site
set site = new SiteInfo
site.SiteID = "01"
site.SiteName = "Microsoft"
set session("formdata") = site

response.redirect "edit.asp"
%>

the code in edit.asp:
<%
if isObject(session("formdata") then
response.write session("formdata").SiteID
end if
%>

the error occured at line "response.write" :
object can not support the property or method: SiteID

Did you copy and paste this code? If so, you're missing a ) at the following line

if isObject(session("formdata") then
 
L

Lichunlin

Patrice,

Thanks a lot, It can work in the same page, just can not when redirect to another page.

I store the object in session scope just because I want to transfer the object into another page. If you have other more useful way to do so, please let me know, thanks.

Best regards
lichunlin
 
L

Lichunlin

Dear Aaron,

I just want to class to encapsulate all properties, I feel it useful.And I store the object into session scope just because I want to transfer into other asp page, the new page can access the object. If you have other useful way to do so, please feel free to let me know. Thanks a lot.

Best Regards
lichunlin
 
P

Patrice

A bit hard without the whole picture. Generally data are listed and a A href
link allows to go on the edit page with the id on the querystring. The whole
data are then retrieved from the db for editing (genrally the list has
anyway a subset of all the fields).

As a side note, you can also have an object stores its properties using the
session object instead of storing the object itself...

Patrice

--

Lichunlin said:
Patrice,

Thanks a lot, It can work in the same page, just can not when redirect to another page.

I store the object in session scope just because I want to transfer the
object into another page. If you have other more useful way to do so, please
let me know, thanks.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top