June 3, 2009

How to Change the URL of an ASP.NET Hyperlink Control at runtime using jQuery




I recently was solving one of the queries at the forums where the user wanted to change the URL of a Hyperlink control at runtime. This task becomes very simple using jQuery as shown here



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


<head runat="server">


<title></title>


<script src="Scripts/jquery-1.2.6.js" type="text/javascript"></script>


<script type="text/javascript">


    $(document).ready(function() {


        $("[id$='HyperLink1']").attr("href", "http://www.devcurry.com");


    });    


</script>


</head>


<body>


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


<div>   


    <asp:HyperLink ID="HyperLink1" runat="server"


    NavigateUrl="http://www.dotnetcurry.com">Favorite Site</asp:HyperLink>


</div>


</form>


</body>


</html>




This piece of code changes the url from dotnetcurry.com to devcurry.com



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "How to Change the URL of an ASP.NET Hyperlink Control at runtime using jQuery"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions