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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Using Session Variable in Javascript Method.

Using Session Variable in Javascript Method.

Scheduled Pinned Locked Moved ASP.NET
javascripthelp
4 Posts 2 Posters 5 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.
  • M Offline
    M Offline
    M_Menon
    wrote on last edited by
    #1

    Hi Friends I am trying to pass value to my Session Variable from Javascript method. function TestOne { var stringOne= "test"; Session.Add("Test", stringOne); } I am getting an error Session is undefined. Any suggestions would be appreicated. Thanks

    Cheers Menon

    S 1 Reply Last reply
    0
    • M M_Menon

      Hi Friends I am trying to pass value to my Session Variable from Javascript method. function TestOne { var stringOne= "test"; Session.Add("Test", stringOne); } I am getting an error Session is undefined. Any suggestions would be appreicated. Thanks

      Cheers Menon

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      Session is a Sever object not client, so you cannot access it in javascript code. You have to pass the string to the server either through querystring or through any form field and then get it on the server and add it to the session

      -----

      M 1 Reply Last reply
      0
      • S SABhatti

        Session is a Sever object not client, so you cannot access it in javascript code. You have to pass the string to the server either through querystring or through any form field and then get it on the server and add it to the session

        -----

        M Offline
        M Offline
        M_Menon
        wrote on last edited by
        #3

        Thanks Bhatti, Can you please tell me how do you call a server side method from the Javascript? Thanks

        Cheers Menon

        S 1 Reply Last reply
        0
        • M M_Menon

          Thanks Bhatti, Can you please tell me how do you call a server side method from the Javascript? Thanks

          Cheers Menon

          S Offline
          S Offline
          SABhatti
          wrote on last edited by
          #4

          What are you really trying to do? You are in ASP.NET forum which means you have an idea how web forms works. So basically you add a ASP:Button in you page and onclientclick you call the javascript function, in that function you change the value of any hidden field or regular textbox and submit the form. And on server side you add the click handler to the button and in that eevnt handler you get the value of that field. Please go through quickstart tutorials[^] to understand the whole flow. e.g. you will call the following javascript function onclicentclick of the button: function TestOne() { // stringOne is asp:hidden field document.myform.stringOne.value = 'stringOne'; docuemt.myform.submit(); } and on server side in event handler for click event of button you will do this: Session["Test"] = stringOne.Value;

          -----

          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