Correct order of overrides for a composite control based on an abstract one
-
01-10-2019 - |
Question
I'm writing a set of C# composite web server controls for displaying dialog boxes.
I want to have one abstract class which handles the basic layout and things like titles of the control, then have a set of derived ones which render child controls at a specific point.
I forsee three distincts methods: renderOpeningHtml
handled by the abstract class, renderCustomControls
as done by the derived class, and renderClosingHtml
by the abstract class again, except I can't figure the life cycle of a CompositeControl and what methods to use when.
Solution
Never mind, figured it.
Used public override void RenderBeginTag(HtmlTextWriter writer)
and RenderEndTag
for the abstract control, and RenderContents
for the derivatives.
OTHER TIPS
If you don't have to do your own HTML rendering you could also consider deriving from UserControl
and just adding to your Controls
collection. The word "composite" seems to point in that direction.