Get C# session variable using javascript

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

    #1

    Get C# session variable using javascript

    I am new to web development at all but maintaining a .NET
    site that utilizes .apsx pages using vbscript,
    javascript,and C#.

    There is a function I am doing that I only can find out
    how to do in javascript (direct url post to variable then
    close window), however now I need to access a session
    variable from that javascript. I could do it from a C#
    page doing the following:

    (string)HttpCon text.Current.Se ssion["myLearning Url"];

    Anyone know how I can do it in javascript?

    thanks


  • John Timney \(Microsoft MVP\)

    #2
    Re: Get C# session variable using javascript

    The session variables belong to the web server, and are held in the session
    collection on the server, your javascript runs within the client, as part of
    the page request output. The easiest way to access it from javascript would
    be to put it in a hidden field in your page output and access it as a simple
    html field in your client side javascript.

    --
    Regards

    John Timney (Microsoft ASP.NET MVP)
    ----------------------------------------------
    <shameless_auth or_plug>
    Professional .NET for Java Developers with C#
    ISBN:1-861007-91-4
    Professional Windows Forms
    ISBN: 1861005547
    Professional JSP 2nd Edition
    ISBN: 1861004958
    Professional JSP
    ISBN: 1861003625
    Beginning JSP Web Development
    ISBN: 1861002092
    </shameless_autho r_plug>
    ----------------------------------------------

    "Joe" <joe_cool_jr@ho tmail.com> wrote in message
    news:012a01c356 cd$2f5d8b90$a60 1280a@phx.gbl.. .[color=blue]
    > I am new to web development at all but maintaining a .NET
    > site that utilizes .apsx pages using vbscript,
    > javascript,and C#.
    >
    > There is a function I am doing that I only can find out
    > how to do in javascript (direct url post to variable then
    > close window), however now I need to access a session
    > variable from that javascript. I could do it from a C#
    > page doing the following:
    >
    > (string)HttpCon text.Current.Se ssion["myLearning Url"];
    >
    > Anyone know how I can do it in javascript?
    >
    > thanks
    >
    >[/color]


    Comment

    • John Timney \(Microsoft MVP\)

      #3
      Re: Get C# session variable using javascript

      The session variables belong to the web server, and are held in the session
      collection on the server, your javascript runs within the client, as part of
      the page request output. The easiest way to access it from javascript would
      be to put it in a hidden field in your page output and access it as a simple
      html field in your client side javascript.

      --
      Regards

      John Timney (Microsoft ASP.NET MVP)
      ----------------------------------------------
      <shameless_auth or_plug>
      Professional .NET for Java Developers with C#
      ISBN:1-861007-91-4
      Professional Windows Forms
      ISBN: 1861005547
      Professional JSP 2nd Edition
      ISBN: 1861004958
      Professional JSP
      ISBN: 1861003625
      Beginning JSP Web Development
      ISBN: 1861002092
      </shameless_autho r_plug>
      ----------------------------------------------

      "Joe" <joe_cool_jr@ho tmail.com> wrote in message
      news:012a01c356 cd$2f5d8b90$a60 1280a@phx.gbl.. .[color=blue]
      > I am new to web development at all but maintaining a .NET
      > site that utilizes .apsx pages using vbscript,
      > javascript,and C#.
      >
      > There is a function I am doing that I only can find out
      > how to do in javascript (direct url post to variable then
      > close window), however now I need to access a session
      > variable from that javascript. I could do it from a C#
      > page doing the following:
      >
      > (string)HttpCon text.Current.Se ssion["myLearning Url"];
      >
      > Anyone know how I can do it in javascript?
      >
      > thanks
      >
      >[/color]


      Comment

      Working...