Thanks - I new it would be an easy answer!!!
Unfortunately, that was a klugy answer. You don't have to create an object
variable. All you need to do is test if the value is null before attempting
to assign it to a typed variable. Example:
string str; // declare your string
variable.
if (Session["abc"] != null) // Check if Session reference is null
str = (string) Session["abc"]; // Cast the Session object as a string
(or whatever it is) and assign it
This is much more efficient code. Also, it will work with any data type
stored in Session. Just change the cast.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
Tony said:
Thanks - I new it would be an easy answer!!!
Sacha said:
Hello...
You have to use an Object :
object o = System.Web.HttpContext.Current.Session["abc"] ;
string str = string.Empty ;
if (o != null)
str = o.ToString() ;
Tony said:
how do I check if the data in the session object is null before
extracting
it.
The following throws an error if the Session object has not already been
created.
string str = System.Web.HttpContext.Current.Session["abc"].ToString();
Thanks