开发者

pass query string from aspx to html back to aspx, using javascript, link problem

开发者 https://www.devze.com 2023-02-05 14:43 出处:网络
I am passing a querystring from my previous page to this page and then i want to pass it to the next page, but it isn\'t working.

I am passing a querystring from my previous page to this page and then i want to pass it to the next page, but it isn't working.

<script type="text/javascript">
           function qs(search_for) {
        var query = window.location.search.substring(1);
        var parm开发者_如何转开发s = query.split('&');
        for (var i=0; i<parms.length; i++) {
            var pos = parms[i].indexOf('=');
            if (pos > 0  && search_for == parms[i].substring(0,pos)) {
                return parms[i].substring(pos+1);;
            }
        }
        return "";
    }
    </script>

here is the link

<a href="http://www.TEST.com/TEST/TEST/TEST.aspx?comp=" & <script type="text/javascript"> document.write(qs("comp")); </script> & "name=test" >CLICK HERE </a></font></b></p>


Probably easier, more flexible, and more maintainable to just stick it in a hidden field and then retrieve it with a simple document.getElementById().


  • Page 1 Creates URL querystring

  • Page 2 add this to your second page
    <asp:hiddenfield runat="server" id="hdncomp" value=""/> <asp:hiddenfield runat="server" id="hdnname" value=""/>

    Now, in your Page 2 Load event run the following code.

    Me.hdncomp = Request.QueryString("comp")
    Me.hdnname = Request.QueryString("name")
    
  • Finally, when you go to Page 3 Use the values from hdncomp and hdnname as your parameter values. For example:

Response.Redirect("page3.aspx?comp=" & hdncomp & "&name=" & hdnname)

Untested code


well, your syntax is very wrong. you cannot write a new element before closing the first elements tag : <element <element2 /> /> . here's a function that you can use :

function createLink(address,param,text){
   address += ((address.indexOf('?') == -1) ? "?" : "&") 
      + param 
      + "="
      + qs(param);
    document.write(''+text+'');
}
and then, when you want to insert the desired link by inserting a script tag calling the "createLink" function with the desired parameters :
<script type="text/javascript">
createLink("http://www.TEST.com/TEST/TEST/TEST.aspx?name=test","comp","CLICK HERE");
<script/>

Hope this helps!

p.s. : you should probably use only one semicolon and not two at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消