How can I add a handler for the click event of every single generated button?
For example:
Button btn = new Button();
btn.ID = "delete_" + i.ToString();
btn.Click += degerate
{
callFunction(i);
};
Whenever I try pressing the button, it'll only affect calling the function for the last inserted click event. Any suggestions for a fix?
Within the loop you used to declare your buttons, use the following snippet:
Don't forget that "funcName" must match the EventHandle delegate.
Then all your buttons will share the same Event Code, but each event is bound to it's own button.
You can access all info of each button, by casting the sender as the specific object type you're using, for example: