Thursday, March 22, 2012

Session Variables

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
>
>.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" <ptakja@.NOSPAM.corning.com> wrote in message
news:8eb301c35b69$62ce8060$a001280a@.phx.gbl...
> 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" <kevin@.takempis.com> wrote in message
news:OaUHXi3WDHA.1620@.TK2MSFTNGP12.phx.gbl...
> 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" <tierscheiss1977@.hotmail.com> wrote in message
> news:uM5PwY3WDHA.2568@.tk2msftngp13.phx.gbl...
> > 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" <ptakja@.NOSPAM.corning.com> wrote in message
> > news:8eb301c35b69$62ce8060$a001280a@.phx.gbl...
> > > 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" <tierscheiss1977@.hotmail.com> wrote in message
news:OKRSgL4WDHA.2268@.TK2MSFTNGP11.phx.gbl...
> I apoligize, I'm using VB.Net.
> "Kevin Spencer" <kevin@.takempis.com> wrote in message
> news:OaUHXi3WDHA.1620@.TK2MSFTNGP12.phx.gbl...
> > 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" <tierscheiss1977@.hotmail.com> wrote in message
> > news:uM5PwY3WDHA.2568@.tk2msftngp13.phx.gbl...
> > > 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" <ptakja@.NOSPAM.corning.com> wrote in message
> > > news:8eb301c35b69$62ce8060$a001280a@.phx.gbl...
> > > > 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
> > > > > > > > > > >.
> > > > >

0 comments:

Post a Comment