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. Access a javescript var from codebehind

Access a javescript var from codebehind

Scheduled Pinned Locked Moved ASP.NET
questioncsharpjavadatabasetools
4 Posts 2 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.
  • B Offline
    B Offline
    brian55
    wrote on last edited by
    #1

    First, I have a var in java script I need to access in my c# code. How do I do this? Second, I use a droplist in another frame. I want to use the var from the jave script to be used to locate the associated selected index. What I have is the variable name and what I need is its index (I think. I then want to display the field in the droplist box and retrieve all assocated records. Thanks Brian

    G 1 Reply Last reply
    0
    • B brian55

      First, I have a var in java script I need to access in my c# code. How do I do this? Second, I use a droplist in another frame. I want to use the var from the jave script to be used to locate the associated selected index. What I have is the variable name and what I need is its index (I think. I then want to display the field in the droplist box and retrieve all assocated records. Thanks Brian

      G Offline
      G Offline
      gnjunge
      wrote on last edited by
      #2

      Put the variable into a Hidden Field, and after postback you can retreive it using : Request.Form["hiddenField"] Gidon

      B 1 Reply Last reply
      0
      • G gnjunge

        Put the variable into a Hidden Field, and after postback you can retreive it using : Request.Form["hiddenField"] Gidon

        B Offline
        B Offline
        brian55
        wrote on last edited by
        #3

        Sounds like a solution. Being a neophyte I need more direction. For example I have JS function function getSomething(); { var Info = getName(); } the var Info is what I need in my c# code. So how do I put the car into a hidden field? Thanks Brian

        G 1 Reply Last reply
        0
        • B brian55

          Sounds like a solution. Being a neophyte I need more direction. For example I have JS function function getSomething(); { var Info = getName(); } the var Info is what I need in my c# code. So how do I put the car into a hidden field? Thanks Brian

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

          Hi Brian, First of all you have to make your hidden field: <input name="varInfo" id="varInfo" type="hidden"> To write to this field via javascript you can use the following code: document.getElementById("varInfo").value = "something"; or document.all["varInfo"].value = "something"; to get info from this field: alert(document.getElementById("varInfo").value) or alert(document.all["varInfo"].value) And now to read the value in your C# code after postback you simple do: C# string varInfo = Request.Form["varInfo"]; VB.NET dim varInfo as string = Request.Form(“varInfo”) Hope this helps you, Regards, Gidon

          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