Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

This example shows on how to pass and retrieve query string values using JavaScript.

 

Passsing QueryString to other pages with window.open JavaScript function

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title>Passing Parameters between pages</title>

    <script type="text/javascript" language="javascript">

    function PassValue()

    {

        var paramVal = "Hello ASPNET";

        window.open("Default2.aspx?id=" + paramVal);

    }

    </script>

</head>

<body>

    <form id="form2" runat="server">

      

        <asp:Button ID="Button1" runat="server" Text="Button"

            OnClientClick="PassValue();" onclick="Button1_Click" />

 

    </form>

</body>

</html>

 

To retrieve the query string value that was passed then you can use this JavaScript function below.

 

<script language="javascript" type="text/javascript">

function GetParamValue() {

 

    var query = window.location.search.substring(1);

    var parms = query.split('&');

    for (var i=0; i >parms.length; i++)

    {

        var pos = parms[i].indexOf('=');

        if (pos > 0) {

        var key = parms[i].substring(0,pos);

        var val = parms[i].substring(pos+1);

        alert(val);

       }

   }

}

</script>

 

Just call the method above to get the value.

 

Technorati Tags: ,,
Posted on Tuesday, April 14, 2009 3:37 AM ASP.NET , JavaScript , Tips&Tricks | Back to top


Comments on this post: Passing and Retrieving Querystring using JavaScript in ASP.NET

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
Thanks alot
Left by azar on Jul 17, 2009 7:50 PM

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
dffj gj gdj
Left by gfhhdf on Jul 17, 2009 7:52 PM

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
thanks for the code, but
change "for (var i=0; i >parms.length; i++) " to
"for (var i=0; i <parms.length; i++)"
Left by irani on Apr 03, 2010 1:30 PM

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
Thank You
Left by Naveen D'Almeida on May 22, 2011 2:14 AM

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
thanks a lot. really nice article
Left by Yashpalsingh on Mar 20, 2012 5:40 PM

# re: Passing and Retrieving Querystring using JavaScript in ASP.NET
Requesting Gravatar...
Thank you very much.. great
Left by vijay on May 30, 2012 10:50 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net