O'Reilly logo

Programming ASP.NET, Second Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Custom control New Project window

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required