I've been developing a composite web control lately to provide numeric paging for a web form. One problem I hit was how to change the structure of the child controls after handling a postback event. The typical order of events for a composite control is:
Load -> CreateChildControls -> Handle Postback -> Render
I was dynamically creating some of the child controls based on fields that could be modified by the Postback events. The problem was, as you can see from the order above, the child controls are created before the fields are set.
Thankfully I found this post on .NET 247 by Arthur Mnev. He had exactly the same problem and had found a neat solution. If you set the controls ChildControlsCerated flag to False in the event handler, the .net framework will then regenerate the child controls after the event handler has completed. It does incur a penalty as the CreateChildControls method is run twice, but it works very nicely. As he points out you do have to make sure the that the controls are created is the correct order the first tmie the code runs, but in most cases this will not be an issue.
To get round the double running of the code, he does mention that he 'changed it to redirect itself to its own page with Get Parameters instead of events'. Something else for me to take a look at soon...!