Skip to content

How Do I find the ID of the button that was clicked?

Don Feist

Asked Jun 28, 2007, 11:56 AM EDT1 answer
Share
LinkedInX
I have a table with several rows. The last cell in each row has a button with the text of 'Edit'. Each button has an id of btnEditLevel+N. The N is an incremental identifer. I want to know which button was clicked so I can change the backcolor of the row that holds the cell that holds the button that was clicked. I can use Request.Form[] but all I get is the button text, not the button ID.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I found it. In the Edit_Click event you pass (object sender, System.EventArgs e). Then you declare a local object of the same type as the sender, in this case a button like so: Button edit = (Button)sender; That also gave it all the details of the sending button. So you can then reference the sending buttons id but looking at string EditID = edit.ID. And now you have the button ID of the button that was clicked.
    0