'If statement that targets multiple buttons C# ASP.NET
How do I make an if statement that targets multiple buttons in ASP ? For example, I want to make an if statement for 52 buttons to have green color, and when I click on them a textbox should get the text of the button and finally after clicking on the send button, one of the buttons should turn red. This is all done with a small table in SQL server management. NOTE: The last two textboxes are just for cosmetic purposes. The textbox that needs to get the text or number of the button is the "Broj Sedista" field.

Solution 1:[1]
You can try making a single event for all those buttons.
protected void btn_Click (object sender, EventArgs e){
Button btn = sender as Button;
if(btn.Background == Color.green){
textFieldName.Text = "Your text";
}
}
The sender argument represents the control who started the action, so you can convert it to a button and access its properties.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Inkling00 |
