Using
$("a").attr("href", "http://www.google.com/")
will modify the href of all hyperlinks to point to Google. You probably want a somewhat more refined selector though. For instance, if you have a mix of link source (hyperlink) and link target (a.k.a. "anchor") anchor tags:
<a name="MyLinks"></a>
<a href="http://www.codeproject.com/">The CodeProject</a>
...Then you probably don't want to accidentally add href
attributes to them. For safety then, we can specify that our selector will only match <a>
tags with an existing href
attribute:
$("a[href]") //...
Of course, you'll probably have something more interesting in mind. If you want to match an anchor with a specific existing href
, you might use something like this:
$("a[href='http://www.google.com/']").attr('href', 'http://www.live.com/')
This will find links where the href
exactly matches the string http://www.google.com/
. A more involved task might be matching, then updating only part of the href
:
$("a[href^='http://stackoverflow.com']")
.each(function()
{
this.href = this.href.replace(/^http:\/\/beta\.stackoverflow\.com/,
"http://stackoverflow.com");
});
The first part selects only links where the href starts with http://stackoverflow.com
. Then, a function is defined that uses a simple regular expression to replace this part of the URL with a new one. Note the flexibility this gives you - any sort of modification to the link could be done here.
If you're not concerned about people messing the with query string you can use that and then just get the data out in the next page during the Page_Init or Page_Load using:
HttpContext.Current.Request.Item("EmployeeID")
However, I'm a fan of not using the query string because people tamper with it. You can use the PostBackUrl property of your hyperlink (if you use the asp linkbutton), and in the next page you can use the Page.PreviousPage object to access any objects from the previous page.
<asp:LinkButton ID="lnkEmployeeLink23232" runat="server" CommandArgument="23232" PostBackUrl="NextPage.aspx" Text="Employee Name" />
You'll have to check for IsCrossPagePostBack on the first page to make sure you don't fire databinding unnecessarily, but at that point you should be able to get to the control that fired the postback and from there get the command argument which would be the employee id in question.4
http://msdn.microsoft.com/en-us/library/ms178139.aspx
http://www.developerfusion.com/code/4687/cross-page-postbacks-in-aspnet-20/
Best Answer
You can generate a link(href) that goes to
and in the code for the second page you can retrieve this value via Request.Querystring("firstname"). But with webforms and postbacks there are other ways of doing this. After getting the selected firstname (preferably in a variable) you can use it for whatever data retrieval methods you want.
Also, I really would recommend against using the name as a key in your database. If this is an experiment to learn, I guess it doesn't matter, but the second you want to enter two people named "John" into your database you have run into trouble.