Home All Groups Group Topic Archive Search About
Author
10 Dec 2005 8:50 PM
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

Author
10 Dec 2005 9:12 PM
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;
        }
    }
Show quoteHide quote
"Vi" wrote:

> 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