Name

Control

Synopsis

The Control class defines properties, methods, and events that all server controls in ASP.NET require. ASP.NET controls do not inherit directly from this class; instead, they inherit from either the System.Web.UI.HtmlControls.HtmlControl or the System.Web.UI.WebControls.WebControl class, both of which inherit from the Control class. Similarly, the Page and UserControl classes inherit from TemplateControl, which inherits from this class.

The Control class contains many of the typical members you would expect in a control, including properties that reference the parent Web Form (Page) and a collection of contained controls (Controls). The EnableViewState property determines whether ASP.NET maintains the control’s state automatically by using a hidden field. The ViewState property provides the StateBag collection of state information.

Most Control methods are used transparently by the ASP.NET framework, such as Render(), which generates the HTML output of a control, and LoadViewState() and SaveViewState(), which manage view state automatically. One interesting method is DataBind(), which binds controls to arrays or data tables. If you are creating a page that interacts with information from a database, you may need to use this method frequently.

You can inherit from the Control class to create a simple ASP.NET control. Override the Render() method so that the control can generate its own output by using the supplied HtmlTextWriter. If you are creating a composite ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.