You don't need to explicity create the children, the framework will do that
automatically when they are needed, i.e. before rendering, or earlier if a
child need to load state or fire an event.
One situation you need to be aware of that the framework is not currently
covering is when you access a child by index, i.e:
[C#]
Control ctrl = Controls[3];
if when this code runs children were not yet created (because of any of the
previous considered reasons, i.e.: rendering,etc) then they WONT be
automatically created. So you're required to call base.EnsureChildControls
before accesing the Controls collection by index. A much better solution
would be to override the get accesor for the Controls property of your
composite control and call EnsureChildControls in there, i.e:
[C#]
public override ControlCollection Controls {
get {
base.EnsureChildControls ();
return base.Controls;
}
}
The next version of ASP.NET will include the scenario missing from the v1.x
bits by introducing a new CompositeControl base class that would do exactly
the same check in the Controls property get accesor as I described above.
Good luck with your custom control development!
--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
"Iain" <> wrote in message
news:%...
> Thanks Victor.
>
> So, to summarise this approach makes sense but I should be careful of the
> details.
>
> Specifically, I should set
>
> >>base.ChildControlsCreated = false;
>
> whenever I do something in an event that may affect the hierarchy.
>
> What I wasn't clear on is when I should recreate the hierarchy?
>
> Specifically, will the framework call CreateChildControls at an opportune
> time automatically (before Render) or do I need to do a check at some
point
> (OnPreRender or Render?) and recreated them as needed?
>
> Thanks again - sometimes you've done something 'right', but you can't
quite
> believe it!
>
>
> Iain
>
> "Victor Garcia Aprea [MVP]" <> wrote in message
> news:...
> > Hi Iain,
> >
>
>