Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Custom Controls Children

Hey all. A friend sent me this question but before I spend too long fishing up an answer, has anyone encountered this?

I've created a custom tab control that implements WebControl and I'm using persistChildren(true) and parseChildren(false). However, when I do a postback, all the controls that are contained within the tab control lose their ViewState functionality and I can no longer pass the values back to the server. The tricky part here is this, none of the controls within the tabs are static, everything that goes in the tab is done in the HTML editor. I know if I had controls that I knew would be there I could create Properties to save the values to the ViewState. Is there a way to loop through the controls at render and create custom Properties to use the ViewState? Or, Can I implement IPostBackDataHandler to get the values?

Thanks much

David Seruyange
Monday, September 6, 2004

Pay close attention to the order of events.

Specifically in Init you should have access to your child controls, but not to reliably access the parent.

All Init's on the page fire before LoadViewState

You probably want to do any custom rehydration in OnLoad (before events) or PreRender (after events).

Monday, September 6, 2004

I don't fully understand the question, but two important points are:
- Override CreateChildControls to rebuild your control tree.  In the case of a postback you can rebuild it using data you have previously saved in ViewState
- It's too late to update ViewState in the render phase.  You need to save it before the SaveViewState phase, e.g. in OnPreRender.
I'd suggest you post the question with sample source on a dotnet newsgroup.

Or read the book at the following link which is the best book I've seen on server control development.  If you don't want to buy the book, download the sample code from the "companion content" link on the page - there are some good examples of composite controls.

Tuesday, September 7, 2004

*  Recent Topics

*  Fog Creek Home