Session Variables

  • Thread starter Thread starter J. Ptak
  • Start date Start date
J

J. Ptak

Hey Tibby.

The proper way to create a session variable is:

Session["VarName"] = value;

Or you can use the Add method as:

Session.Add("VarName", value);

Either way will work.

Next to remove an item from the session state:

Session.Remove("VarName");

To clear all items from the session state use:

Session.Clear();

HTH.

Jeff Ptak
 
Just to make sure I'm playing ball here, so, instead of using Dim myVar as
string, then later using myVar="Kiss Me", I would use Session["myVar"]="Kiss
Me", then to reference it, I would use something like
MsgBox(Session["myVar"])
Just to make sure I'm on the same page.

Thanks
Tibby

J. Ptak said:
Hey Tibby.

The proper way to create a session variable is:

Session["VarName"] = value;

Or you can use the Add method as:

Session.Add("VarName", value);

Either way will work.

Next to remove an item from the session state:

Session.Remove("VarName");

To clear all items from the session state use:

Session.Clear();

HTH.

Jeff Ptak

-----Original Message-----
What is the proper way to creating Session Variables and destroying them. I
think this is what my major problem is. And, can that be done also for
ADO.NET objects?

Thanks
Tibby


.
 
I apoligize, I'm using VB.Net.

Kevin Spencer said:
Forget about "MsgBox." That function is not for ASP.Net pages. It is only
used for Windows Forms. Other than that, you are basically corrrect.
However, it is hard to tell whether you're using VB.Net or C# from your
example, as the MsgBox function is a VB.Net function, but your syntax for
the Session variable is C#. Here are 2 examples, using VB.Net and C#:

VB.Net: Session("myVar") = "Kiss Me"
C#: Session["myVar"] = "Kiss Me";

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

Tibby said:
Just to make sure I'm playing ball here, so, instead of using Dim myVar as
string, then later using myVar="Kiss Me", I would use Session["myVar"]="Kiss
Me", then to reference it, I would use something like
MsgBox(Session["myVar"])
Just to make sure I'm on the same page.

Thanks
Tibby

J. Ptak said:
Hey Tibby.

The proper way to create a session variable is:

Session["VarName"] = value;

Or you can use the Add method as:

Session.Add("VarName", value);

Either way will work.

Next to remove an item from the session state:

Session.Remove("VarName");

To clear all items from the session state use:

Session.Clear();

HTH.

Jeff Ptak


-----Original Message-----
What is the proper way to creating Session Variables and
destroying them. I
think this is what my major problem is. And, can that be
done also for
ADO.NET objects?

Thanks
Tibby


.
 
No apology neccessary! That's what we're here for. :)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

Tibby said:
I apoligize, I'm using VB.Net.

Kevin Spencer said:
Forget about "MsgBox." That function is not for ASP.Net pages. It is only
used for Windows Forms. Other than that, you are basically corrrect.
However, it is hard to tell whether you're using VB.Net or C# from your
example, as the MsgBox function is a VB.Net function, but your syntax for
the Session variable is C#. Here are 2 examples, using VB.Net and C#:

VB.Net: Session("myVar") = "Kiss Me"
C#: Session["myVar"] = "Kiss Me";

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

Tibby said:
Just to make sure I'm playing ball here, so, instead of using Dim
myVar
as
string, then later using myVar="Kiss Me", I would use Session["myVar"]="Kiss
Me", then to reference it, I would use something like
MsgBox(Session["myVar"])
Just to make sure I'm on the same page.

Thanks
Tibby

Hey Tibby.

The proper way to create a session variable is:

Session["VarName"] = value;

Or you can use the Add method as:

Session.Add("VarName", value);

Either way will work.

Next to remove an item from the session state:

Session.Remove("VarName");

To clear all items from the session state use:

Session.Clear();

HTH.

Jeff Ptak


-----Original Message-----
What is the proper way to creating Session Variables and
destroying them. I
think this is what my major problem is. And, can that be
done also for
ADO.NET objects?

Thanks
Tibby


.
 
Back
Top