
130
|
Chapter 6: User Controls and Custom Server Controls
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Compositional Controls
As mentioned earlier in the chapter, compositional controls render their output by
combining appropriate controls within the CreateChildControls method, which is
overridden in the custom control.
Example 6-7 shows the C# code for a compositional control that provides simple
functionality for a blog (which is short for web log). The control has two modes:
Add and Display. The mode is determined by the internal member_mode, which
can be accessed by the public Mode property.
Like the NavBar control created in the previous example, the class definition for
the Blog control specifies that the class derives from the Panel control (using C#’s
: syntax), and also implements the INamingContainer interface. The INaming-
Container interface contains no members, so there’s nothing to actually
implement. It’s simply used to tell the ASP.NET runtime to provide a separate
naming scope for controls contained within the custom control. This helps avoid
Figure 6-1. NavBarClient.aspx output