Session Variables

Discussion in 'ASP .Net' started by J. Ptak, Aug 5, 2003.

  1. J. Ptak

    J. Ptak Guest

    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
    >
    >
    >.
    >
     
    J. Ptak, Aug 5, 2003
    #1
    1. Advertising

  2. J. Ptak

    Tibby Guest

    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" <> wrote in message
    news:8eb301c35b69$62ce8060$...
    > 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
    > >
    > >
    > >.
    > >
     
    Tibby, Aug 5, 2003
    #2
    1. Advertising

  3. J. Ptak

    Tibby Guest

    I apoligize, I'm using VB.Net.

    "Kevin Spencer" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:8eb301c35b69$62ce8060$...
    > > > 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
    > > > >
    > > > >
    > > > >.
    > > > >

    > >
    > >

    >
    >
     
    Tibby, Aug 5, 2003
    #3
  4. 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" <> wrote in message
    news:...
    > I apoligize, I'm using VB.Net.
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:8eb301c35b69$62ce8060$...
    > > > > 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
    > > > > >
    > > > > >
    > > > > >.
    > > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Kevin Spencer, Aug 5, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob

    Global Session Variables and Session State

    Earl Teigrob, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,289
    Alvin Bruney
    Dec 17, 2003
  2. =?iso-8859-15?Q?Fabr=EDcio_de_Novaes_Kucinskis?=

    Session Variables assigned to the wrong session?

    =?iso-8859-15?Q?Fabr=EDcio_de_Novaes_Kucinskis?=, Jan 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    719
    Alvin Bruney [MVP]
    Jan 20, 2005
  3. Robert Faulkner
    Replies:
    0
    Views:
    887
    Robert Faulkner
    Jan 28, 2005
  4. Replies:
    1
    Views:
    948
  5. Replies:
    9
    Views:
    984
Loading...

Share This Page