How can I detect which control was clicked?

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.
 
K

Klaus H. Probst

(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top