Session Variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Ptak

    #1

    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("Va rName", 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

    [color=blue]
    >-----Original Message-----
    >What is the proper way to creating Session Variables and[/color]
    destroying them. I[color=blue]
    >think this is what my major problem is. And, can that be[/color]
    done also for[color=blue]
    >ADO.NET objects?
    >
    >Thanks
    >Tibby
    >
    >
    >.
    >[/color]
  • Tibby

    #2
    Re: Session Variables

    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:8eb301c35b 69$62ce8060$a00 1280a@phx.gbl.. .[color=blue]
    > Hey Tibby.
    >
    > The proper way to create a session variable is:
    >
    > Session["VarName"] = value;
    >
    > Or you can use the Add method as:
    >
    > Session.Add("Va rName", 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
    >
    >[color=green]
    > >-----Original Message-----
    > >What is the proper way to creating Session Variables and[/color]
    > destroying them. I[color=green]
    > >think this is what my major problem is. And, can that be[/color]
    > done also for[color=green]
    > >ADO.NET objects?
    > >
    > >Thanks
    > >Tibby
    > >
    > >
    > >.
    > >[/color][/color]


    Comment

    • Tibby

      #3
      Re: Session Variables

      I apoligize, I'm using VB.Net.

      "Kevin Spencer" <kevin@takempis .com> wrote in message
      news:OaUHXi3WDH A.1620@TK2MSFTN GP12.phx.gbl...[color=blue]
      > 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" <tierscheiss197 7@hotmail.com> wrote in message
      > news:uM5PwY3WDH A.2568@tk2msftn gp13.phx.gbl...[color=green]
      > > Just to make sure I'm playing ball here, so, instead of using Dim myVar[/color][/color]
      as[color=blue][color=green]
      > > string, then later using myVar="Kiss Me", I would use[/color]
      > Session["myVar"]="Kiss[color=green]
      > > 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:8eb301c35b 69$62ce8060$a00 1280a@phx.gbl.. .[color=darkred]
      > > > Hey Tibby.
      > > >
      > > > The proper way to create a session variable is:
      > > >
      > > > Session["VarName"] = value;
      > > >
      > > > Or you can use the Add method as:
      > > >
      > > > Session.Add("Va rName", 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
      > > > >
      > > > >
      > > > >.
      > > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Kevin Spencer

        #4
        Re: Session Variables

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

        --
        HTH,

        Kevin Spencer
        Microsoft MVP
        ..Net Developer
        All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

        Complex things are made up of
        lots of simple things.

        "Tibby" <tierscheiss197 7@hotmail.com> wrote in message
        news:OKRSgL4WDH A.2268@TK2MSFTN GP11.phx.gbl...[color=blue]
        > I apoligize, I'm using VB.Net.
        >
        > "Kevin Spencer" <kevin@takempis .com> wrote in message
        > news:OaUHXi3WDH A.1620@TK2MSFTN GP12.phx.gbl...[color=green]
        > > Forget about "MsgBox." That function is not for ASP.Net pages. It is[/color][/color]
        only[color=blue][color=green]
        > > 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[/color][/color]
        for[color=blue][color=green]
        > > 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" <tierscheiss197 7@hotmail.com> wrote in message
        > > news:uM5PwY3WDH A.2568@tk2msftn gp13.phx.gbl...[color=darkred]
        > > > Just to make sure I'm playing ball here, so, instead of using Dim[/color][/color][/color]
        myVar[color=blue]
        > as[color=green][color=darkred]
        > > > string, then later using myVar="Kiss Me", I would use[/color]
        > > Session["myVar"]="Kiss[color=darkred]
        > > > 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:8eb301c35b 69$62ce8060$a00 1280a@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("Va rName", 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
        > > > > >
        > > > > >
        > > > > >.
        > > > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...