tags:

views:

28

answers:

1

I am adding user controls dynamically to a page which all adhere to an interface. I want to be able to find these controls again upon Postback. I tried looking through the control collection but to no avail? Please help. Thanks.

+1  A: 

The controls need to be added again on PostBack. They should be added early in the page lifecycle, e.g. PageInit.

Remember that when a PostBack occurs, the control collection has to be built from scratch. Where the controls are added to the page declaratively - as markup in the .aspx - the ASP.NET framework automatically instantiates and adds the controls, but you still need to manually add any dynamically created controls. Adding the controls early in the page life-cycle ensures that viewstate and postback data are handled correctly, and any events are raised.

JulianM