O'Reilly logo

ASP.NET in a Nutshell by Matthew MacDonald, G. Andrew Duthie

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

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

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