I have a page where I create a dynamic table, containing dynamic controls which raise events. It works, but I wan't to re-generate that table in some events (so after page_load) to print table modifications.
I understand the problem, its that at this moment, my controls aren't persisted in the viewstate because they are created after page_load, and their events are not raised. But how could I do this ?
Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
generateTable(); // When pass just here, it works well
}
private void generateTable()
{
Table tbl = new Table();
// Here I create my table with controls
tableContainer.Controls.Clear(); // tableContainer is a Panel fixed in aspx page
tableContainer.Controls.Add(tbl);
}
protected void txt_TextChanged(object sender, EventArgs e)
{
// Do some stuff to change values in the table
generateTable(); // Re-generate (but events will not be raised)
}
UPDATE 1:
I thought about something (which complicate my development), but I should do generateTable which creates all my lines and controls and call it on each page_load. And in the other hand create another method which populate controls ? So in events, I call the second one.
But my table is generated dynamically, and controls can also be added after an event (I have a dropdownlist which create a new line and control in the table, so I'm stuck also here cause I won't see the line at the first postback ?)