I have spent around 3 hours today debugging a custom control which was required to capture simple text. The problem was that whatever I entered in the text box was not being persisted after a post back. I tried the following during the time:
- Use FindControl to resolve member variable controls – failed
- Change CreateChildControls method to create only if not Page.IsPostBack – failed, worse – controls were not rendered after post back
- Use a static method for performing my logic and use Page.FindControl in that method – failed.
- Save control tree to ViewState – failed, TextBox is not serializable
- Use WebControl instead of Panel as base class, and use [PersistChildren(true)] – failed. No effect.
- Use CompositeControl instead of WebControl and use [PersistChildren(true)] – worked!
- Use CompositeControl without [PersistChildren(true)] worked!