How to know which LinkButton clicked?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On a webform, I am dynamically creating a bunch of LinkButton's. The number of LinkButton's being created will depend on the data that's coming back

When a Linkbutton is clicked, and it doesn't have an onclick event defined, the page still goes through postback. But how do I know what caused the postback.

I would simply like to know the ID of the LinkButton that was clicked.

Your help is appreciated
 
Thanks Dune, I'll check that out.
I was getting stumpted because Request.Form["__EVENTTARGET"] was returning ""
 
In the example in the MSDN article, the LinkButtons are pre-defined in the webform. In my code, I'm adding the Controls directly to the page in the codebehind
Thus, I'm not able to define the OnCommand property of the LinkButton in the codebehind when I create the LinkButton control.

In concept, this is a great idea, because I would set the OnCommand property of every LinkButton control on the page to the same event.
 
Figured it out, when creating the LinkButton in code

oLinkButton.Command += new CommandEventHandler(this.lnkButton_Click)

and then I define my even

private void lnkButton_Click(Object sender, CommandEventArgs e
{Response.Write(e.CommandName.ToString());}
 
Back
Top