ASP.NET Custom Controls
- Declaring a Simple Custom Control
- Extending Existing Web Controls
- Creating ViewState-Enabled Control Properties
- Creating a Composite Control
- Creating a Data-bound Control
- Creating a Templated Control
- Dynamically Adding Controls to a Web Form
- Using the Treeview IE Web Control
- Using the TabControl and PageView IE Web Controls
- Using the ToolBar IE Web Control
- Data-binding a TreeView Control
- Installing a Component in the Global Assembly Cache (GAC)
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.
Developing ASP.NET Server Controls and Components by Nikhil Kothari and Vandana Datye (Microsoft Press; ISBN 0735615829)