Using session variables in .cs file

D

dana lees

Hello,

I am using session variables in a cs class file. I am inserting a sortedList
to a session variable like this:

System.Web.HttpContext.Current.Session["EventsList"] = EventsSortedList;

Later on, when i want to use this value by:

EventsSortedList =
(SortedList)System.Web.HttpContext.Current.Session["EventsList"];

i get an error "Specified cast is not valid". When debugging i see that the
value entered to the session is a string and not a sortedArray.

What am i doing wrong?

Thanks,

Dana
 
H

Hans Kesting

Hello,
I am using session variables in a cs class file. I am inserting a sortedList
to a session variable like this:

System.Web.HttpContext.Current.Session["EventsList"] = EventsSortedList;

Later on, when i want to use this value by:

EventsSortedList =
(SortedList)System.Web.HttpContext.Current.Session["EventsList"];

i get an error "Specified cast is not valid". When debugging i see that the
value entered to the session is a string and not a sortedArray.

What am i doing wrong?

Thanks,

Dana

See if you didn't accidentally also use "EventsList" to store some
string (what is the string - it might give you a hint).
It *should* work the way you used it.

Hans Kesting
 
D

dana lees

I did use Session["EventsList"] already , thank you...

Hans Kesting said:
Hello,

I am using session variables in a cs class file. I am inserting a sortedList
to a session variable like this:

System.Web.HttpContext.Current.Session["EventsList"] = EventsSortedList;

Later on, when i want to use this value by:

EventsSortedList =
(SortedList)System.Web.HttpContext.Current.Session["EventsList"];

i get an error "Specified cast is not valid". When debugging i see that the
value entered to the session is a string and not a sortedArray.

What am i doing wrong?

Thanks,

Dana

See if you didn't accidentally also use "EventsList" to store some
string (what is the string - it might give you a hint).
It *should* work the way you used it.

Hans Kesting
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top