Creating User Controls
In addition to the built-in server controls in the .NET Framework, you can
also build your own controls to be placed on Web Forms. ASP.NET supports
two different types of user-created controls: user controls and custom
controls. The creation of custom controls is beyond the scope of this book,
but it's simple to create user controls. These controls are basically saved
pages (or pagelets) that act as self-contained controls.
For example, you may wish to create a menu system along the left side of
every page in your site, where each menu item is built from a database. You
might also want to place a standard logo and header on each page. What you
need is some way to include standard pages, or parts of pages, within each
of your pages.
User controls provide this functionality and are the replacement for
#include files in ASP.NET. Figure 6.4 displays the output you might want to
generate. In this example, the image and header "Northwind Traders" are
both in one user control. The menu going down the left side is another
control.
Figure 6.4. User controls output HTML on the client side.
Figure 6.5 shows the same Web page in design mode. As you can see, these
user controls are simply placeholders. You can see the full UI for such
controls by opening the file where you built them within your project.
Figure 6.5. User controls do not display any HTML on the server side; they
are just placeholders.