How to Get URL Parameters or Query String Value using Javascript in Asp.Net C# VB.Net

Query String is used to transfer data from one page to another page. Here in this example I will explain How one can get URL Parameters or Query String Value using Javascript from client side. In this example I will manually pass URL parameters or Query string to Default.aspx page & from that page I will retrieve values using Javascript. So that you can apply the same technique whenever required.

Related Article:
How to Get URL Parameters or Query String Value using JQuery in Asp.Net C# VB.Net

Objective/Outcome:
How to Get URL Parameters or Query String Value using Javascript in Asp.Net Csharp VB.Net

To do the Example add a Label Control First:

    <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
    <asp:Button ID="Button1" runat="server" Text="Read Query String using Javascript" OnClientClick="return Read_Query_String();"/>

Javascript Code Example to get URL Parameter or Query String Value:

<script type="text/javascript">
    function Read_Query_String() {
        var s_Current_Page_URL = window.location.search.substring(1);
        var sQueryStrings = s_Current_Page_URL.split('&');
        for (var i = 0; i < sQueryStrings.length; i++) {
            var sQueryStringParameters = sQueryStrings[i].split('=');
            if (sQueryStringParameters.length > 1)
                document.getElementById("<%=Label1.ClientID%>").innerHTML += sQueryStringParameters[0] + "=" + sQueryStringParameters[1] + "<br/>"
        }
        return false;
    }
</script>

Hope now you can read URL Parameter or Query String Values from client side using Javascript.

Download Code Example C#        Download Code Example VB.Net

Posted in .Net, Asp.net, C#, Client, Javascript, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

     

*