Custom Controls
In addition to creating user controls, which are essentially reusable small web pages, you can also create your own compiled custom controls. There are three ways to create custom controls:
Create a derived custom control by deriving from an existing control.
Create a composite control by grouping existing controls together into a new compiled control.
Create a full custom control by deriving from System.Web.UI.WebControls.WebControl.
Composite controls are most similar to user controls. The key difference is that composite controls are compiled into a DLL and used as you would any server control.
To get started, you’ll create a Web Control Library in which you’ll create the various custom controls for this chapter. Open Visual Studio .NET and choose New Project. In the New Project Window, select either Visual C# Projects or Visual Basic Projects and create a Web Control Library called CustomControls, as shown in Figure 14-7.

Figure 14-7. Custom control New Project window
You’ll notice that Visual Studio has created a complete custom control named WebCustomControl1. Before examining this control, create a Web Application to test it. From the File menu choose New Project (Ctrl-Shift-N) and create a project named CustomControlWebPage in the same directory. Be sure to choose the “Add to Solution” radio button, as shown in Figure 14-8.
Figure 14-8. Add custom control web page ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access