They rely on
the base class implementation of Render() provided by the System.Web.UI.Control class that
locates the Controls collection and calls Render() for each child control. This recursive call, in
turn, causes the child controls to either render or do the same with their children, recursively
walking through the render tree. In the end, we have a nice HTML output.
Although the composite control doesn??™t override the Render() method, it needs to override the
CreateChildControls() method that is called by the ASP.NET Framework. This method is called
to give the custom server control the opportunity to create its Controls collection, populating
it with the appropriate child controls for rendering the desired output.
One extra task we need to perform is to override the Controls property exposed by the base
Control class. This ensures that when an outside client attempts to access our composite control,
the child control content will always be created and ready for access.
The EnsureChildControls() method does the work for us. Calling it will call
CreateChildControls() if the child controls have not been initialized. Overriding Controls is
always recommended in composite controls.
It is also recommended to call EnsureChildControls() for properties in a composite control
right at the beginning of the Get and Set methods.
Pages:
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140