ASP.NET developers typically look to the user control as the first option for creating controls
due to its ease of construction and simplicity. Building a user control closely mirrors the construction
techniques and technical details of a web form. User controls support drag-and-drop
development with the Visual Studio control toolbox, a fully editable design surface in the IDE,
and a code-behind class file structure to support a separation of UI and logic programming.
User controls are built in two ways:
??? From scratch
??? By taking out reusable content from an existing web form
The first method is used when enough planning and design work is done ahead of time to
figure out which portions of the UI are going to be reused on the web site. The second technique
CHAPTER 2 ?– ENCAPSULATING FUNCT IONALITY IN ASP.NET 53
results from refactoring the content of a site after it has been built to make it modular and
easier to maintain.
The MenuUserControl User Control
Our first example takes advantage of the declarative nature of the user control to encapsulate a
simple hyperlink menu as a control that we build from scratch. The control is pure, static HTML
without a single embedded server control. It consists of nothing more than a list of fixed hyperlinks
to a variety of web sites.
Pages:
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113