Sessions in C#

W

Will

ok.. I've created a namespace and a class in an assembly
file and included into my .aspx page as a custom control.
On that aspx page I store a string in a session as follows:

Session["strColor"] = "blue";

Now, inside my assembly file I want to retrieve that
variable. I have tried everything.. I have an instance of
the current session state as follows:

HttpSessionState mySession = ((HttpSessionState)
HttpContext.Current.Session);

now when I try to do something like:

private string strTemp = mySession["strColor"].ToString();

I get the follwing error:

A field initializer cannot reference the nostatic field,
method, or property 'myNamespace.myClass.mySession'

What does this error mean? And how can I retrieve
strColor? I have seriously tried a thousand things..
please be specific in your answers, thanks A LOT in
advance.

Will
 
K

Kevin Spencer

Declare the field without initializing it, and in the Constructor method for
the class, assign it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 

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,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top