This prevents any chance of accessing a
child control before it is created. We deviate from this practice for the TableCompCustomControl
control, because the X and Y properties must be set and available before we can create the control
hierarchy. Otherwise, we wouldn??™t know what dimensions to use for the table.
Our implementation of CreateChildControls() calls into routines responsible for adding
the child controls representing the header and the HTML table of the control, which are named
BuildHeader() and BuildTable(), respectively. It is also the linkage point for evaluating the X
and Y dimensions of the table.
BuildHeader() demonstrates the use of an HtmlGenericControl control from the System.
Web.UI.HtmlControls namespace to render the
content. This control was chosen due to its
lack of built-in styling capabilities to keep the example simple. We build up the string content
of the control by using the StringBuilder class. This class is a more efficient way of building up
strings in .NET than concatenating literals as Strings, because StringBuilder uses a buffer.
Variables of type String are immutable, and a concatenation operation actually builds a third
string from the two strings brought together, literal or otherwise.
Pages:
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141