
Custom Server Controls | 123
User and
Server Controls
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Custom Server Controls
For the reasons cited earlier in the chapter, user controls are not always the ideal
choice for reuse. User controls tend to be very good for quickly reusing existing
user interface elements and code, but custom server controls are much better for
developing reusable building blocks for multiple web applications.
A custom server control is, in its essence, a class that derives from either the
Control or
WebControl class of the System.Web.UI namespace, or from one of the
classes that derive from these controls. Custom server controls can be used in
your ASP.NET Web Forms pages in very much the same way you use the built-in
server controls that come with ASP.NET. There are two primary categories of
custom server controls:
Rendered controls
Rendered controls consist largely of custom rendering of the text, tags, and
any other output you desire, which may be combined with the rendered
output of any base class from which your control is derived. Rendered
controls override the Render method of the control from which they derive.
This method is called automatically by the page containing the control when
it’s time for the control output to be displayed.
Compositional controls
Compositional controls get their name from the ...