Question: Difference between strMyVar and Session("strMyVar")

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Question: Difference between strMyVar and Session("strMyVar")

    If I have a variable I want to share in my application what is the
    difference between just declaring a variable (Dim strMyVar as String) and
    using a session variable (Session("strMyVar"))?

    When should I use a session variable and when should I just declare it like
    normal?

    Thanks in advance!


    VB Programmer Guest

  2. Similar Questions and Discussions

    1. What is the difference between a DNS "zone" and a DNS "domain"?
      Gurus, What is the difference between a DNS "zone" and a DNS "domain"? I've been studying DNS a lot and grasp the concept, but I want to hear...
    2. Question about redirecting to a "session expired" page...
      This may sound trivial but I cannot figure out how to do this... When a logged in user's session expires, I want that user redirected back to the...
    3. Which is faster? Dim dv As New DataView(session("myDataTable")) or CType(session("myDataTable"))
      Hello, let's say my session("myDataTable") is type of DataTable Now what is faster? a) Dim dv As New DataView(session("myDataTable")) b) Dim...
    4. what's the difference between ". cmd" and "cmd" in shell script??
      Thank u very much!! -- Zhao YouBing, Ph.D student State Key Lab of CAD&CG,Zhejiang University, Hangzhou, 310027, P.R.China Tel :...
  3. #2

    Default Re: Question: Difference between strMyVar and Session("strMyVar")

    When a user signs on to your website a unique session id is created for
    them. This session id is stored on their computer as a cookie. When you
    place an object into a session variable that object remains in server memory
    between trips to the client and may be "reclaimed" from one page to the
    next.

    When you declare a variable on a per page basis such as: Dim strMyVar as
    String the object is only persisted in memory while the page is built and
    then destroyed after the output is sent to the client.

    You should use regular variables whenever an object does not need to persist
    beyond a single request to the server. And use session variables when you
    need to reference an object from one request to the server to another.

    I hope this helps.

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    news:ONLW3GpWDHA.2284@TK2MSFTNGP10.phx.gbl...
    > If I have a variable I want to share in my application what is the
    > difference between just declaring a variable (Dim strMyVar as String) and
    > using a session variable (Session("strMyVar"))?
    >
    > When should I use a session variable and when should I just declare it
    like
    > normal?
    >
    > Thanks in advance!
    >
    >

    S. Justin Gengo Guest

  4. #3

    Default Re: Question: Difference between strMyVar and Session("strMyVar")

    Thanks for the great response!

    So would you use session variables where you needed a "global" variable?

    "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    news:%235WsRLpWDHA.1640@TK2MSFTNGP10.phx.gbl...
    > When a user signs on to your website a unique session id is created for
    > them. This session id is stored on their computer as a cookie. When you
    > place an object into a session variable that object remains in server
    memory
    > between trips to the client and may be "reclaimed" from one page to the
    > next.
    >
    > When you declare a variable on a per page basis such as: Dim strMyVar as
    > String the object is only persisted in memory while the page is built and
    > then destroyed after the output is sent to the client.
    >
    > You should use regular variables whenever an object does not need to
    persist
    > beyond a single request to the server. And use session variables when you
    > need to reference an object from one request to the server to another.
    >
    > I hope this helps.
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > [url]www.aboutfortunate.com[/url]
    >
    > "Out of chaos comes order."
    > Nietzche
    > "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    > news:ONLW3GpWDHA.2284@TK2MSFTNGP10.phx.gbl...
    > > If I have a variable I want to share in my application what is the
    > > difference between just declaring a variable (Dim strMyVar as String)
    and
    > > using a session variable (Session("strMyVar"))?
    > >
    > > When should I use a session variable and when should I just declare it
    > like
    > > normal?
    > >
    > > Thanks in advance!
    > >
    > >
    >
    >

    VB Programmer Guest

  5. #4

    Default Re: Question: Difference between strMyVar and Session("strMyVar")

    Thanks!

    Is a cookie automatically created if I use session("xxx")? Or do I have to
    enable something? (I do realize that the client has to have cookies enabled
    on their end.)

    "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    news:eieMhXpWDHA.656@tk2msftngp13.phx.gbl...
    > Exactly!
    >
    > There are also application variables. They are also global, but they are
    not
    > user specific. (i.e. If you set a session variable = 2 for one user and =
    1
    > for another, when each session variable is recalled on a server request
    each
    > user's session variable reflects their individual setting. An application
    > level variable is the same for everyone. If user 1 sets it = 1 and then
    user
    > 2 sets it = 2 when user 1 makes a new request the application variable
    will
    > be = 2.)
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > [url]www.aboutfortunate.com[/url]
    >
    > "Out of chaos comes order."
    > Nietzche
    > "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    > news:%230KOfSpWDHA.2352@TK2MSFTNGP12.phx.gbl...
    > > Thanks for the great response!
    > >
    > > So would you use session variables where you needed a "global" variable?
    > >
    > > "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    > > news:%235WsRLpWDHA.1640@TK2MSFTNGP10.phx.gbl...
    > > > When a user signs on to your website a unique session id is created
    for
    > > > them. This session id is stored on their computer as a cookie. When
    you
    > > > place an object into a session variable that object remains in server
    > > memory
    > > > between trips to the client and may be "reclaimed" from one page to
    the
    > > > next.
    > > >
    > > > When you declare a variable on a per page basis such as: Dim strMyVar
    as
    > > > String the object is only persisted in memory while the page is built
    > and
    > > > then destroyed after the output is sent to the client.
    > > >
    > > > You should use regular variables whenever an object does not need to
    > > persist
    > > > beyond a single request to the server. And use session variables when
    > you
    > > > need to reference an object from one request to the server to another.
    > > >
    > > > I hope this helps.
    > > >
    > > > --
    > > > S. Justin Gengo, MCP
    > > > Web Developer
    > > >
    > > > Free code library at:
    > > > [url]www.aboutfortunate.com[/url]
    > > >
    > > > "Out of chaos comes order."
    > > > Nietzche
    > > > "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    > > > news:ONLW3GpWDHA.2284@TK2MSFTNGP10.phx.gbl...
    > > > > If I have a variable I want to share in my application what is the
    > > > > difference between just declaring a variable (Dim strMyVar as
    String)
    > > and
    > > > > using a session variable (Session("strMyVar"))?
    > > > >
    > > > > When should I use a session variable and when should I just declare
    it
    > > > like
    > > > > normal?
    > > > >
    > > > > Thanks in advance!
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    VB Programmer Guest

  6. #5

    Default Re: Question: Difference between strMyVar and Session("strMyVar")

    It's created automatically.

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    news:e7naoopWDHA.1812@TK2MSFTNGP11.phx.gbl...
    > Thanks!
    >
    > Is a cookie automatically created if I use session("xxx")? Or do I have
    to
    > enable something? (I do realize that the client has to have cookies
    enabled
    > on their end.)
    >
    > "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    > news:eieMhXpWDHA.656@tk2msftngp13.phx.gbl...
    > > Exactly!
    > >
    > > There are also application variables. They are also global, but they are
    > not
    > > user specific. (i.e. If you set a session variable = 2 for one user and
    =
    > 1
    > > for another, when each session variable is recalled on a server request
    > each
    > > user's session variable reflects their individual setting. An
    application
    > > level variable is the same for everyone. If user 1 sets it = 1 and then
    > user
    > > 2 sets it = 2 when user 1 makes a new request the application variable
    > will
    > > be = 2.)
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > [url]www.aboutfortunate.com[/url]
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > > "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    > > news:%230KOfSpWDHA.2352@TK2MSFTNGP12.phx.gbl...
    > > > Thanks for the great response!
    > > >
    > > > So would you use session variables where you needed a "global"
    variable?
    > > >
    > > > "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    > > > news:%235WsRLpWDHA.1640@TK2MSFTNGP10.phx.gbl...
    > > > > When a user signs on to your website a unique session id is created
    > for
    > > > > them. This session id is stored on their computer as a cookie. When
    > you
    > > > > place an object into a session variable that object remains in
    server
    > > > memory
    > > > > between trips to the client and may be "reclaimed" from one page to
    > the
    > > > > next.
    > > > >
    > > > > When you declare a variable on a per page basis such as: Dim
    strMyVar
    > as
    > > > > String the object is only persisted in memory while the page is
    built
    > > and
    > > > > then destroyed after the output is sent to the client.
    > > > >
    > > > > You should use regular variables whenever an object does not need to
    > > > persist
    > > > > beyond a single request to the server. And use session variables
    when
    > > you
    > > > > need to reference an object from one request to the server to
    another.
    > > > >
    > > > > I hope this helps.
    > > > >
    > > > > --
    > > > > S. Justin Gengo, MCP
    > > > > Web Developer
    > > > >
    > > > > Free code library at:
    > > > > [url]www.aboutfortunate.com[/url]
    > > > >
    > > > > "Out of chaos comes order."
    > > > > Nietzche
    > > > > "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
    > > > > news:ONLW3GpWDHA.2284@TK2MSFTNGP10.phx.gbl...
    > > > > > If I have a variable I want to share in my application what is the
    > > > > > difference between just declaring a variable (Dim strMyVar as
    > String)
    > > > and
    > > > > > using a session variable (Session("strMyVar"))?
    > > > > >
    > > > > > When should I use a session variable and when should I just
    declare
    > it
    > > > > like
    > > > > > normal?
    > > > > >
    > > > > > Thanks in advance!
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    S. Justin Gengo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139