Pages

Wednesday, 3 July 2013

How To Get QueryString Value Or Get QueryString Parameter Values using jQuery in c# Asp.Net

How To  Get QueryString Value Or Get QueryString Parameter Values using jQuery in c# Asp.Net


Program:

.Aspx File:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Current Page Url Parameter values</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        var name = GetParameterValues('username');
        var id = GetParameterValues('userid');
        $('#spn_UserName').html('<strong>' + name + '</strong>');
        $('#spn_UserId').html('<strong>' + id + '</strong>');
    });
    function GetParameterValues(param) {
        var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < url.length; i++) {
            var urlparam = url[i].split('=');
            if (urlparam[0] == param) {
                return urlparam[1];
            }
        }
    }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>UserName: <span id="spn_UserName"></span></p>
<p>UserId: <span id="spn_UserId"></span></p>
</div>
</form>
</body>
</html>

Demo:

How To  Get QueryString Value Or Get QueryString Parameter Values using jQuery in c# Asp.Net
How To  Get QueryString Value Or Get QueryString Parameter Values using jQuery in c# Asp.Net

No comments:

Post a Comment