Datasheet

because both user controls and custom controls can be used as Web Parts, you can drag customization
components from both the Toolbox and Solution Explorer (full-fledged Web Parts appear in the
Toolbox). Whether you are building Web Parts, custom controls, or user controls, you can add your
own properties, methods, and events to them.
User Controls
While the focus of this book is on custom controls and Web Parts, user controls shouldn’t be ignored. For
developers, the major difference between user controls and custom controls is in ease of development
a powerful incentive to use user controls. User controls provide an easy way to create reusable controls:
If you know how to create a Web page in ASP.NET, then you know how to create a user control. As an
example, you can add controls to your user control the same way that you add controls to a Web page:
by dragging and dropping the controls onto a design surface. Figure 1-1 shows a user control in Design
view in Visual Studio .NET.
Figure 1-1
Of course, nothing comes for free: In order to gain this ease of development, user controls have several
limitations. The first major limitation in the functionality of user controls is that they cannot inherit from
other ASP.NET controls, while a custom control can inherit from other controls. The capability to inherit
from other controls enables you, for instance, to create a custom control that inherits from the ASP.NET
ListBox control and extends that control.
However, this limitation often just means thinking about the problem differently: If you want to create
a user control that functions like a ListBox, you could just drop a list box on your user control and then
add any new methods, properties, or events that you want (with a custom control, you would have to do
4
Chapter 1
05_57860x ch01.qxd 10/4/05 9:26 PM Page 4