Base Classes and Rendering


To implement rendering functionality in your control, you have to override the rendering methods of the Control class or the WebControl class. The work that you must do depends on the base class from which your control derives. In Chapter 5, we briefly discussed how to choose the base control class from which to derive your control. Now we'll take a closer look at how rendering determines that choice.

If you want to implement a control that renders markup other than HTML (such as XML or WML) or renders a nonvisual HTML element, you should derive from the Control class. You should also derive from Control if your control merely renders literal HTML without offering your users the ability to alter the appearance of the rendered elements. To explain these guidelines, let's look at examples of controls that derive from Control . The System.Web.UI.WebControls namespace contains four controls that derive from Control ”Literal , PlaceHolder , Repeater , and Xml . The Xml control renders XML markup, and the Literal control renders literal text specified by a page developer. The text rendered by Literal could contain HTML markup, but the Literal control itself does not expose any properties that enable its users to modify the appearance of the rendered content. Similarly, the Repeater and PlaceHolder controls do not render visual HTML elements or expose properties related to appearance.

If you want to implement a control that renders a visual HTML element ”that is, HTML associated with a visual representation in a Web browser ”you should derive your control from the WebControl class. The WebControl class has built-in functionality for rendering styles that enable a user to specify the appearance of the rendered element. All the controls in the System.Web.UI.WebControls namespace (barring the four controls discussed in the previous paragraph) derive directly or indirectly from WebControl . These include simple controls (such as Button and TextBox ) that represent HTML form elements, as well as complex controls (such as Calendar , DataList , and DataGrid ).



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net