This topic has not yet been rated - Rate this topic

PageAdapter Class

Adapts a Web page for a specific browser and provides the base class from which all page adapters inherit, directly or indirectly.

System.Object
  System.Web.UI.Adapters.ControlAdapter
    System.Web.UI.Adapters.PageAdapter

Namespace:  System.Web.UI.Adapters
Assembly:  System.Web (in System.Web.dll)
public abstract class PageAdapter : ControlAdapter

The PageAdapter type exposes the following members.

  Name Description
Protected method PageAdapter Infrastructure. Initializes a new instance of the PageAdapter class.
Top
  Name Description
Protected property Browser Gets a reference to the browser capabilities of the client making the current HTTP request. (Inherited from ControlAdapter.)
Public property CacheVaryByHeaders Gets a list of additional HTTP headers by which caching is varied for the Web page to which this derived page adapter is attached.
Public property CacheVaryByParams Gets a list of additional parameters from HTTP GET and POST requests by which caching is varied for the Web page to which this derived page adapter is attached.
Protected property ClientState Gets an encoded string that contains the view and control states data of the Web page to which this derived page adapter is attached.
Protected property Control Gets a reference to the control to which this control adapter is attached. (Inherited from ControlAdapter.)
Protected property Page Gets a reference to the page where the control associated with this adapter resides. (Inherited from ControlAdapter.)
Protected property PageAdapter Gets a reference to the page adapter for the page where the associated control resides. (Inherited from ControlAdapter.)
Top
  Name Description
Protected method 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. (Inherited from ControlAdapter.)
Protected method CreateChildControls Creates the target-specific child controls for a composite control. (Inherited from ControlAdapter.)
Public method DeterminePostBackMode Determines whether the Web page is in postback and returns a name/value collection of the postback variables.
Protected method 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. (Inherited from ControlAdapter.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Protected method GetPostBackFormReference Returns a DHTML code fragment that the client browser can use to reference the form on the page that was posted.
Public method GetRadioButtonsByGroup Retrieves a collection of radio button controls specified by groupName.
Public method GetStatePersister Returns an object that is used by the Web page to maintain the control and view states.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method 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. (Inherited from ControlAdapter.)
Protected method 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. (Inherited from ControlAdapter.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnInit Overrides the OnInit method for the associated control. (Inherited from ControlAdapter.)
Protected method OnLoad Overrides the OnLoad method for the associated control. (Inherited from ControlAdapter.)
Protected method OnPreRender Overrides the OnPreRender method for the associated control. (Inherited from ControlAdapter.)
Protected method OnUnload Overrides the OnUnload method for the associated control. (Inherited from ControlAdapter.)
Public method RegisterRadioButton Adds a radio button control to the collection for a specified radio button group.
Protected method Render Generates the target-specific markup for the control to which the control adapter is attached. (Inherited from ControlAdapter.)
Public method RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) Renders an opening hyperlink tag that includes the target URL to the response stream.
Public method RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) Renders an opening hyperlink tag that includes the target URL and an access key to the response stream.
Protected method RenderChildren Generates the target-specific markup for the child controls in a composite control to which the control adapter is attached. (Inherited from ControlAdapter.)
Public method RenderEndHyperlink Renders a closing hyperlink tag to the response stream.
Public method RenderPostBackEvent(HtmlTextWriter, String, String, String, String) Renders a postback event into the response stream as a hyperlink, including the encoded and possibly encrypted view state, and event target and argument.
Public method RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String) Renders a postback event into the response stream as a hyperlink, including the encoded and possibly encrypted view state, an event target and argument, a previous-page parameter, and an access key.
Protected method RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String, Boolean) Renders a postback event into the response stream as a hyperlink, including the encoded view state, an event target and argument, a previous-page parameter, and an access key.
Protected method SaveAdapterControlState Saves control state information for the control adapter. (Inherited from ControlAdapter.)
Protected method SaveAdapterViewState Saves view state information for the control adapter. (Inherited from ControlAdapter.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method TransformText Transforms text for the target browser.
Top

The PageAdapter class is an abstract class that adapts a Web page for a specific class of browsers, defined by the markup language that the browser uses (for example, HTML or XHTML). Much of the adaptability in rendering behavior can be encapsulated in the specialized text writer classes that derive from the HtmlTextWriter class, so it is not always necessary to provide a page adapter.

Most members of derived page adapters are called from the Page class or from control adapters. First, the Page class or control adapters detect the presence of the derived page adapter, and then call the member, or provide the functionality if the page adapter is not present.

The members of the PageAdapter class provide the following functionality:

  • The CacheVaryByHeaders and CacheVaryByParams properties define additional HTTP headers and HTTP GET and POST parameters that can be used to vary caching. They are called during cache initialization from the Page class.

  • The GetStatePersister method returns an object that can be used to persist the combined view and control states of the page. It is referenced from the PageStatePersister property if a derived page adapter is present.

  • The GetPostBackFormReference method provides a DHTML code fragment that can be used to reference forms in scripts.

  • The DeterminePostBackMode method returns a collection of the postback variables if the page is in postback. It is called by the .NET Framework instead of the Page.DeterminePostBackMode method if a derived page adapter is present.

  • The RenderBeginHyperlink and RenderEndHyperlink methods are used by control adapters to render hyperlinks if a derived page adapter is present.

  • The RenderPostBackEvent() method renders a hyperlink or postback client tag that can submit the form.

  • The RegisterRadioButton and GetRadioButtonsByGroup methods are used by radio button control adapters to reference the other RadioButton controls in a radio button group.

  • The ClientState property provides access to the combined control and view states of the Page object through the internal ClientState property of the Page class.

  • The TransformText method is used by control adapters to perform device-specific text transformation.

The following code example demonstrates how to derive a class named CustomPageAdapter from the PageAdapter class and override the RenderBeginHyperlink method. The RenderBeginHyperlink method adds an attribute named src to a hyperlink, which contains a reference to the current page. All hyperlinks rendered in pages to which CustomPageAdapter is attached will have the src attribute.


using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;

// A derived PageAdapter class.
public class CustomPageAdapter : PageAdapter
{
    // Override RenderBeginHyperlink to add an attribute that 
    // references the referring page.
    public override void RenderBeginHyperlink(
        HtmlTextWriter writer, string targetUrl,
        bool encodeUrl, string softkeyLabel, 
        string accessKey )
    {
        string url = null;

        // Add the src attribute, if referring page URL is available.
        if( Page != null && Page.Request != null &&
            Page.Request.Url != null )
        {
            url = Page.Request.Url.AbsoluteUri;
            if( encodeUrl )
                url = HttpUtility.HtmlAttributeEncode( url );
            writer.AddAttribute( "src", url );
        }

        // Add the accessKey attribute, if caller requested.
        if( accessKey != null && accessKey.Length == 1 )
            writer.AddAttribute( "accessKey", accessKey );

        // Add the href attribute, encode the URL if requested.
        if( encodeUrl )
            url = HttpUtility.HtmlAttributeEncode( targetUrl );
        else
            url = targetUrl;
        writer.AddAttribute( "href", url );

        // Render the hyperlink opening tag with the added attributes.
        writer.RenderBeginTag( "a" );
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ