Find the source of an event

V

Vi

Hi,
I'm trying to attach a code behind method to two different LinkButton
controls on my page.

How can I find out which of the controls fired up the event in the code
behind method that handles the event?

Thanks
 
P

Phillip Williams

The Commnad event passes a parameter of type CommandEventArgs that has a
value for the CommandName attribute of the LinkButton control, e.g.

<asp:LinkButton ID="LinkButton1" runat=server CommandName ="DeleteARecord"
OnCommand ="LinkButtons_Command"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat=server CommandName ="AddARecord"
OnCommand ="LinkButtons_Command" ></asp:LinkButton>

protected void LinkButtons_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "DeleteARecord":
//add code to delete
break;
case "AddARecord":
//add code to add a record
break;
}
}
 

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,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top