How can I detect which control was clicked?

  • Thread starter Thread starter needin4mation
  • Start date Start date
N

needin4mation

Hi, I have two links, one function. Both links are wired via the
onclick to the same function.

I want to test in the function which link was clicked and code
accordingly. How?

I have looked around on google groups and could not find it.

Any help is appreciated.

<td><asp:LinkButton id="LinkButton1" runat="server"
OnClick="LinkButton2_Click1">previous</asp:LinkButton>

<asp:LinkButton id="LinkButton2" runat="server"
OnClick="LinkButton2_Click1">next</asp:LinkButton></td>

protected void LinkButton2_Click1(object sender, EventArgs e)
{
how can I tell which link clicked me?
}

Thank you again for any help.
 
(e-mail address removed) wrote in @i40g2000cwc.googlegroups.com:
Hi, I have two links, one function. Both links are wired via the
onclick to the same function.

I want to test in the function which link was clicked and code
accordingly. How?

The 'sender' parameter in the handler delegate is a reference to the
control that initiated the event. So if you have a reference to the link
control itself at the page level, i.e.:

protected System.Web.UI.WebControl.Hyperlink Link1;

Then you can do this:

private void OnLinkClick(object sender, ...) {
if (sender == Link1) {
...
}
else if (sender == Link2) {
...
}
}

and so on.
 
Back
Top