ASP.NET Developer’s Cookbook – Chapter 3: Custom Controls

3.0. Introduction

One of the most powerful features of ASP.NET is its support for custom server controls and components. ASP.NET ships with dozens of built-in controls, and developers can easily extend these controls or write their own controls from scratch. Server controls can be used to encapsulate complex user interface logic or business rules, and can benefit from design-time support like drag-and-drop and toolbox support and property builders. Custom controls pick up where User Controls leave off, providing greater flexibility, reusability, and a better design time experience, but with some added complexity. In this chapter you will find examples covering some of the most common server-control techniques.

Custom controls as a rule inherit directly or indirectly from the System.Web.UI.Control base class. Controls that are visible on a page should inherit directly or indirectly from System.Web.UI.WebControls.WebControl, which provides properties like Style, which you can use to determine the look of the control on the page. Custom controls can be built in a number of ways. Some simply override the Render() method, thus determining the HTML output in place of the control at runtime. Others, known as composite controls, act as containers for other controls. Others inherit from existing fully functional controls to create more specific versions of these controls or to enhance their functionality.

Controls in ASP.NET can support data-binding as well as templates. In fact, there is easily enough information about building controls to fill an entire book (and in fact such a book exists and is listed at the end of this section), so this chapter attempts to cover the most common techniques that you will use, leaving much of the theory to other books dedicated to control building.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read