I have several buttons being created dynamically in cells of a table that is also being created dynamically.
In the first column of each row, I adds the button like this:
Button btnIdentifier = new Button();
btnIdentifier.Text = uniqueID;
btnIdentifier.Click += (s, e) =>
{
Button button = s as Button;
GetResults(button.Text);
};
cell.Controls.Add(btnIdentifier);
But when I click on the button, the event does not fire. The table that was previously dynamically created (along with the buttons) get removed from the page.
I know it's because after it does a postback, the buttons no longer exist on the page. But I don't know how to remedy that.
How can I create the buttons in the Page_Load
method if they need to be created dynamically and may be different every time the code is executed? (It's for this same reason I can't just create them on the page and set Visible=false
).
Thanks.