I have a custom user control that consists of a dynamic list of controls, along with a static button that is declared (along with the OnClick declaration) on the aspx page. The button shows or hides a panel containing the dynamic control list.
I am finding a problem that I presume is related to the dynamically added controls, where the button event method (even though it is not added dynamically), only fires on the second click. I think this has something to do with the fact that the button event method is wired up before the controls are created, and the event method gets wired up incorrectly on postback when there are suddenly new dynamic controls on the page. On the second click it works because the dynamic controls have all been created and are simply being persisted.(Please someone correct me if I am wrong - I spent all day tracking this down :( )
My question is, how do I fix this? I tried wiring up the event for the button dynamically as well, but I am not sure what order to put all these declarations in. Any ideas?