I have a Placeholder where a table is dynamically added on page load (everything loads fine and I can see control[0] when debugging without a problem. When button is clicked to reset the form, I try to access that table at control[0] and get "index out of range". I have researched quite a bit and can not find why that is happening.
Here is the code when page loads:
private void LoadTable()
{
Table oTable = new Table();
//gather table row and cell info here - table loads fine on page
PlaceHolder1.Controls.Add(oTable);
}
This code fires when button is clicked:
private void ResetForm()
{
//clear out textboxes and dropdown lists
Table oTable = new Table();
oTable = (Table)PlaceHolder1.Controls[0]; // this is where problem occurs
}
and the HTML:
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
I hope that it isn't something obvious that I'm missing, since I'm still fairly new to programming. Any help is appreciated!