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. How do you create a query string with JavaScript and access the values in Code Behind

How do you create a query string with JavaScript and access the values in Code Behind

Scheduled Pinned Locked Moved ASP.NET
javascriptdatabasetutorialquestion
8 Posts 4 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
    AndyASPVB
    wrote on last edited by
    #1

    Hi I would like to know how to construct a query string with JavaScript and to then be able to access the passed values in the code behind. Can someone show me how? Thanks

    A C S 3 Replies Last reply
    0
    • A AndyASPVB

      Hi I would like to know how to construct a query string with JavaScript and to then be able to access the passed values in the code behind. Can someone show me how? Thanks

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      AndyASPVB wrote:

      how to construct a query string with JavaScript

      What does it mean? Yes, if are able to create the string, you can save the string in server side hidden field and then can access it from codebehind.

      Cheers ! Abhijit Codeproject MVP

      1 Reply Last reply
      0
      • A AndyASPVB

        Hi I would like to know how to construct a query string with JavaScript and to then be able to access the passed values in the code behind. Can someone show me how? Thanks

        C Offline
        C Offline
        carlecomm
        wrote on last edited by
        #3

        Hi, You can try this: function QueryString(qs) { s = location.href; s = s.replace("?","?&").split("&"); re = ""; for(i=1;i<s.length;i++) { if(s[i].indexOf(qs+"=")==0) { re = s[i].replace(qs+"=",""); } } return re; } then you can do sth to access the pass to anywhere.

        1 Reply Last reply
        0
        • A AndyASPVB

          Hi I would like to know how to construct a query string with JavaScript and to then be able to access the passed values in the code behind. Can someone show me how? Thanks

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          A similar thing is done in XMLHttpRequest...GET method to be more specific! create a URL with query stings and call it. Access the querystrings using Request.QueryString["QSName"]

          A 2 Replies Last reply
          0
          • S Sandeep Mewara

            A similar thing is done in XMLHttpRequest...GET method to be more specific! create a URL with query stings and call it. Access the querystrings using Request.QueryString["QSName"]

            A Offline
            A Offline
            AndyASPVB
            wrote on last edited by
            #5

            Hi I am almost there, but I am getting a problem with multiple postbacks. You see, I need to have my javascript function on an asp:panel scrollbar, and in my js, I wrote this: function scrollPos(position) { window.location.href="default.aspx?scrollPos="+position.scrollTop; } When I move the scrollbar, the page constantly posts back in an uncontrollable manner, flickering away! How do I stop this, so it is smooth and the page is workable?

            S 1 Reply Last reply
            0
            • S Sandeep Mewara

              A similar thing is done in XMLHttpRequest...GET method to be more specific! create a URL with query stings and call it. Access the querystrings using Request.QueryString["QSName"]

              A Offline
              A Offline
              AndyASPVB
              wrote on last edited by
              #6

              Sorry, but just to add, my web page refreshes every few minutes. Therefore, is it possible to have the query string parameters attached to the url then when the page is posted back?

              1 Reply Last reply
              0
              • A AndyASPVB

                Hi I am almost there, but I am getting a problem with multiple postbacks. You see, I need to have my javascript function on an asp:panel scrollbar, and in my js, I wrote this: function scrollPos(position) { window.location.href="default.aspx?scrollPos="+position.scrollTop; } When I move the scrollbar, the page constantly posts back in an uncontrollable manner, flickering away! How do I stop this, so it is smooth and the page is workable?

                S Offline
                S Offline
                Sandeep Mewara
                wrote on last edited by
                #7

                From this reply of yours it looks like you want to maintain scroll position on postbacks. Is that so? If so, there are other ways simpler ones to do it. Why you thought of querystring? Have a look at these: Maintain GridView Scroll Position and Header Inside Update Panel[^] Maintain Scroll Position in Panel, Div[^] P.S.: At any time you can update your question or conversation if needed.

                A 1 Reply Last reply
                0
                • S Sandeep Mewara

                  From this reply of yours it looks like you want to maintain scroll position on postbacks. Is that so? If so, there are other ways simpler ones to do it. Why you thought of querystring? Have a look at these: Maintain GridView Scroll Position and Header Inside Update Panel[^] Maintain Scroll Position in Panel, Div[^] P.S.: At any time you can update your question or conversation if needed.

                  A Offline
                  A Offline
                  AndyASPVB
                  wrote on last edited by
                  #8

                  Hi I have already looked at the maintain scroll bar position and this only works on the browser scroll bar and not on asp:panel. Plus I actually have a number of panels which could all be in different positions, which is why I need to use JS and query strings

                  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