Datasheet
Studio .NET designer, it’s going to take much longer to lay out your user interface. And, without the
benefit of Visual Studio .NET’s IntelliSense support for writing client-side code, it’s going to take longer
to write bug-free client-side code, also.
You should use a custom control only if there is some compelling reason for not using a user control. In
the days of the ASP.NET 1.0 and 1.1, there were several benefits to using custom controls compared to
user controls— custom controls had a design-time interface and could be shared among projects, for
instance. However, with ASP.NET 2.0, some of those differences have gone away. With ASP.NET 2.0,
there are only three reasons that might cause you to consider using a custom control:
❑ You should use a custom control whenever the control will be used in more than one project.
❑ You should use a custom control when your HTML can’t be generated by some combination of
existing ASP.NET controls.
❑ You should use a custom control when you want to extend an existing ASP.NET control (rather
than write all the functionality yourself). While you can extend an existing ASP.NET control by
wrapping it inside a user control, it’s often easier to extend an existing control by inheriting
from the existing control and modifying it in some way.
Web custom controls do offer another benefit: they expose all the code involved in creating a control — a
good thing in a book about creating your own controls.
In the book site example, a user control would be the best choice for the title bar because the title bar is
limited to a single Web site and is built from existing Web server controls. The properties exposed by the
title bar Web Part would allow the code behind a page to insert the text that the page needs. The listing
control described in the case study would be best implemented through a custom control that extends
the ASP.NET DataList control.
Web Parts in Action: Customization
But when should you use a Web Part? First, remember that any control can be used as a Web Part. When
used as a Web Part, user controls and custom controls can be customized in several ways:
❑ The control can be added or removed from the page.
❑ The control’s appearance can be modified.
❑ The control can be moved to a different location on the page.
Users will also be able to set the control’s property values interactively at run time. However, if you
build a control as a Web Part from the ground up, you can give your control even more features — the
capability to pass data between other controls, for instance.
When considering how you can use Web Parts, ask yourself if it’s necessary that you build every page in
your application. Can you improve your productivity by letting your users build parts of the application
for you? This section offers a few examples based on the bookstore application. Your users will certainly
come up with many suggestions for customizing your application by using Web Parts.
16
Chapter 1
05_57860x ch01.qxd 10/4/05 9:26 PM Page 16