Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Asp.Net Session Variable in JavaScript

Asp.Net Session Variable in JavaScript

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nettutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AS 13
    wrote on last edited by
    #1

    Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding

    N G 2 Replies Last reply
    0
    • A AS 13

      Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      var sessionValue = <% Session["value"].ToString() %>

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      A 1 Reply Last reply
      0
      • N N a v a n e e t h

        var sessionValue = <% Session["value"].ToString() %>

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        A Offline
        A Offline
        AS 13
        wrote on last edited by
        #3

        Hello, Thanks Buddy...but its gives me the value undefined... my code is as below. (In JavaScript): var ImageUrl = <% Session["ImageUrl"].ToString(); %> (In ASPX file): HttpContext.Current.Session["ImageUrl"] = "image" + "/" + "it-cover.jpg"; and In case of HiddenField how to do it? HappyCoding

        A key to every Solution

        N 1 Reply Last reply
        0
        • A AS 13

          Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          It's impossible to access session variables from Javascript. The session variables never leaves the server. If you want to use the value from a session varible, you have to copy the value from the session variable and put it in the generated html code, for example by outputting Javascript code that creates a variable that contains the value from the session variable, as Navaneeth suggested.

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          • A AS 13

            Hello, Thanks Buddy...but its gives me the value undefined... my code is as below. (In JavaScript): var ImageUrl = <% Session["ImageUrl"].ToString(); %> (In ASPX file): HttpContext.Current.Session["ImageUrl"] = "image" + "/" + "it-cover.jpg"; and In case of HiddenField how to do it? HappyCoding

            A key to every Solution

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            You need a single quotation (') around it. Try this

            '<% Session["ImageUrl"].ToString(); %>';

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups