Customizes rendering for the derived control to which the adapter is attached, to modify the default markup or behavior for specific browsers, and is the base class from which all control adapters inherit.
Assembly: System.Web (in System.Web.dll)
Thetype exposes the following members.
|Browser||Gets a reference to the browser capabilities of the client making the current HTTP request.|
|Control||Gets a reference to the control to which this control adapter is attached.|
|Page||Gets a reference to the page where the control associated with this adapter resides.|
|PageAdapter||Gets a reference to the page adapter for the page where the associated control resides.|
|BeginRender||Called prior to the rendering of a control. In a derived adapter class, generates opening tags that are required by a specific target but not needed by HTML browsers.|
|CreateChildControls||Creates the target-specific child controls for a composite control.|
|EndRender||Called after the rendering of a control. In a derived adapter class, generates closing tags that are required by a specific target but not needed by HTML browsers.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|LoadAdapterControlState||Loads adapter control state information that was saved by SaveAdapterControlState during a previous request to the page where the control associated with this control adapter resides.|
|LoadAdapterViewState||Loads adapter view state information that was saved by SaveAdapterViewState during a previous request to the page where the control associated with this control adapter resides.|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|OnInit||Overrides the OnInit method for the associated control.|
|OnLoad||Overrides the OnLoad method for the associated control.|
|OnPreRender||Overrides the OnPreRender method for the associated control.|
|OnUnload||Overrides the OnUnload method for the associated control.|
|Render||Generates the target-specific markup for the control to which the control adapter is attached.|
|RenderChildren||Generates the target-specific markup for the child controls in a composite control to which the control adapter is attached.|
|SaveAdapterControlState||Saves control state information for the control adapter.|
|SaveAdapterViewState||Saves view state information for the control adapter.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Control adapters are components that override certain Control class methods and events in its execution lifecycle to allow browser or markup-specific handling. The .NET Framework maps a single derived control adapter to a Control object for each client request.
An adapter modifies a control for a specific browser or class of browsers or acts as an arbitrary filter on some capability. Typically the adapter is defined by the markup language that the browser uses (for example, XHTML or HTML 3.2). Much of the adaptability in rendering behavior can be encapsulated in the specialized classes that derive from the HtmlTextWriter class. Therefore, it is likely that a single adapter can be used for a number of browser class behaviors or that inclusion of the adaptability in the HtmlTextWriter classes could make the use of a control adapter unnecessary.
An adapter for a control class applies to all controls that inherit from that class, unless more specialized adapters are present. For example, an adapter for the BaseValidator class can be used for all Validator objects.
Adapters typically do not inherit directly from the class, but from one of the target-specific adapter base classes that provide additional functionality specific to the control type and target browser or the particular rendering required.
Controls themselves do not necessarily require an adapter. If controls are extended through composition, generally the child control adapters are sufficient.
Each control has explicit mappings to adapters through the .browser definition files. Thus, any access to the Control.Adapter property uses the HttpBrowserCapabilities object extracted from the browser definition files to perform the lookup for the mapping of the adapter to control.
During processing, the .NET Framework intercepts calls to the overridable methods of a control that could be target-specific. If a control adapter is attached, the .NET Framework calls the associated adapter methods.
The adapter performs rendering for the control through the Render method. If overridden, Render potentially should not call the base class implementation because that performs a call back on the Control.Render method. This might cause the rendering to occur twice, once by the adapter and once by the control.
The Render base method calls back on the Control.Render method of the control. Thus, if you override Render, you should not call the base class implementation unless the rendering you implement is in addition to that provided by Control.Render of the control.
You must ensure that the .NET Framework performs interception for adapters of the child controls. You can do this by calling the RenderChildren base method, which calls the Control.RenderChildren method of the control, from your Render override.
The BeginRender and EndRender methods are called by the control immediately before and after (respectively) the control calls the Render method. If pre- and post-rendering are the only browser-specific processing tasks required, using BeginRender and EndRender might make it unnecessary to override Render. The default behavior of the BeginRender and EndRender methods is to call the corresponding methods of the HtmlTextWriter.
To maintain its own state information, a control adapter can override the SaveAdapterControlState, LoadAdapterControlState, SaveAdapterViewState, and LoadAdapterViewState methods. SaveAdapterControlState, SaveAdapterViewState, LoadAdapterControlState, and LoadAdapterViewState are called when the private control and view states are saved and loaded, respectively.
The OnInit, OnLoad, OnPreRender, and OnUnload base methods call back on the corresponding Control class methods. Thus, any of these methods that are overridden must call their base methods; otherwise, the event associated with the Control class method will not be raised.
Controls and adapters optionally implement the IPostBackDataHandler and IPostBackEventHandler interfaces. The .NET Framework determines whether an adapter exists and whether the adapter implements these interfaces. If it does, the adapter should override the LoadPostData, RaisePostDataChangedEvent, and RaisePostBackEvent methods, as necessary. If the postback data is not recognized in the adapter, it must call back on the control to process it. Subsequent event handlers also must call back on the control.Notes to Inheritors
When you inherit from the class, a control that requires general adapter functionality should have a corresponding adapter base class, named in the pattern ControlTypeAdapter (for example, TextBoxAdapter). The adapter should at a minimum return a strongly-typed instance of the control through its Control property.
Control adapters for a given control type and markup language should be named in the pattern MarkupControlTypeAdapter (for example, XhtmlTextBoxAdapter). Adapters for a control should be implemented in an Adapters subnamespace.
Control adapters should inherit from the appropriate base class and follow the same inheritance model as the control. For example, an adapter for a control inheriting from the Control base class should inherit from either the class or the relevant ControlTypeAdapter class.
Any specialized adapters should be defined for the specialized control under all of the device nodes in configuration .browser files.
A properly implemented control should not assume that an adapter is attached, or that the attached adapter implements a specific interface. Instead, it should check for these before calling.
It is possible to simulate overriding protected event methods in the control, such as the OnClick method of the LinkButton. First, create an adapter class with an OnClick method. Then create a new control derived from LinkButton and override the OnClick method. The overriden OnClick method calls the OnClick method of the adapter. The adapter object is available through the protected Adapter property of the Control class. The Adapter property of the control is null when there is no associated adapter, so any code should check for that condition before calling methods of the adapter.