How to know which LinkButton clicked?

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
 
G

Guest

Thanks Dune, I'll check that out.
I was getting stumpted because Request.Form["__EVENTTARGET"] was returning ""
 
G

Guest

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

Guest

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());}
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top