Zandile Thobeka
Zandile Thobeka

Reputation: 21

How to get the id value of a button using C#?

I have a table which gets data from my database. My table has the columns id,name,url and so forth. Under my ID column I have my settings drop down buttons in each row which I created dynamically using this code:

html.Append("<li><button ID='btnDelete' value='"
    + row[column.ColumnName]
    + "' OnClick='btnDelete_Click' runat='server'>Delete</button></li>");

(This is the delete button in the drop down list)

When inspecting the code while debugging, I can see the ID of each row when I select the delete button. I see it in the "value = ". I want to use that value. Please advice how I can get it on my code.

Debugging my code while inspecting it:

image

Upvotes: 1

Views: 1038

Answers (1)

JustGentle
JustGentle

Reputation: 109

Maybe you can use the sender parameter to get button value:

private void btnDelete_Click(object sender, MouseEventArgs e)        
{
        var senderButton = sender as HtmlButton;
        DeleteById(senderButton.Attributes["Value"]);
}

Untested Code :(

Upvotes: 1

Related Questions