how to find selected hyperlink in asp.net using C#
I have a list of 10 hyperlink on开发者_如何学Go default1.apx. On selecting any hyperlink it redirects to another page and all hyperlinks redirects to the same page default2.aspx. But how can i now which hyperlink is clicked from 10 hyperlinks list in asp.net using C#.
There are a couple of ways, all depending on how you're doing your redirect.
I'm guessing you're using Response.Redirect()
, which means you must be raising a server side event when clicking. In this case all you need to do is check the sender
argument which will give you details of which control was clicked.
Another way is to append the controls' name onto the URL in a GET request. So that each link is slightly different. For example link one could point to default2.aspx?linkthatwasclicked='link1'
where you can substiute link1
accordingly, this value can then be retreived on default2.aspx through the Request.QueryString object.
m.edmondson has got it, another way I've seen is having a "hyperlink.aspx" page which then requests an id:
<a href="hyperlink.aspx?id=1">Link 1</a>
then in the hyperlink.aspx code:
int id = int.Parse(Request.QueryString["id"].ToString());
switch(id)
{
case 1:
// Add a count to a table maybe
// Get the url from the DB here...
string url = GetUrlById(id);
Response.Redirect(url);
break;
}
精彩评论