Class Visibility Question

B

BG

Hey All,

I have a simple understanding of session variables. Can the same thing be
done with a class in ASP.net?

Such as default.aspx contains a new instance of MYClass. So I load
MyClass.MyName = "Fred". Now ,umpteen response.redirects later, umpteen
pages later deep within the web site, I want to display MyClass.MyName and
it will still contain "Fred".

Possible?

Thanks,

BG
 
S

Stefan Kiryazov

One ot the ways to achieve this is to store the object in the Session
and later retrieve it:

Session["MyClass"] = MyClass

The object is stored in the Session object until it is explicitly
removed, the session times out or is emptied in some other way. You
retirieve it when you like with guarantee that it is not changed unless
you have changed it yourself:
MYClass MyClass = (MYClass)Session["MyClass"];
 
D

Daniel Fisher\(lennybacon\)

You can map a property to a session

class X
{
public strinf NAme
{
get
{
return (string)Session["Name"];
}
set
{
Session["Name"] = value;
}
}
}
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top