It also merges the child control styles with the parent styles set
via the ControlStyle property to provide a consistent appearance.
Figure 4-13. The InputBox control and its multiple styles
The first step in building our control is to select the tag that represents the outer shell of
our custom control. For the InputBox we use a
tag. We pass the tag enumeration value to
the base constructor of WebControl so that it knows how to render itself:
public InputBox() : base(HtmlTextWriterTag.Div)
{
}
Because we are building a composite control, we need to override the
CreateChildControls() method so we can populate the internal Controls collection with our
child controls. InputBox adds the Label and TextBox controls, in that order:
override protected void CreateChildControls()
{
ControlsBookLib.Ch04.Label label = new ControlsBookLib.Ch04.Label();
Controls.Add(label);
ControlsBookLib.Ch04.Textbox textbox = new ControlsBookLib.Ch04.Textbox();
Controls.Add(textbox);
}
CHAPTER 4 ?– THE WEBCONTROL BASE C LASS AND CONTROL STYLES 151
The text properties of the child Label and TextBox controls are wired up to top-level properties
of our new InputBox control as LabelText and TextBoxText, respectively.
Pages:
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244