This documentation is archived and is not being maintained.

PageAdapter Class

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

Namespace:  System.Web.UI.Adapters
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public abstract class PageAdapter : ControlAdapter

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" );
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: