PageAdapter 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
修改网页以适应特定的浏览器,并提供所有页面适配器可直接或间接继承的基类。
public ref class PageAdapter abstract : System::Web::UI::Adapters::ControlAdapterpublic abstract class PageAdapter : System.Web.UI.Adapters.ControlAdaptertype PageAdapter = class
    inherit ControlAdapterPublic MustInherit Class PageAdapter
Inherits ControlAdapter- 继承
示例
下面的代码示例演示如何派生从类命名 CustomPageAdapter 的 PageAdapter 类并重写该方法 RenderBeginHyperlink 。 该方法 RenderBeginHyperlink 添加一 src 个名为超链接的属性,该属性包含对当前页的引用。 附加到的页面 CustomPageAdapter 中呈现的所有超链接都将具有该 src 属性。
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" );
    }
}
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Adapters
' A derived PageAdapter class.
Public Class CustomPageAdapter
    Inherits PageAdapter
    ' Override RenderBeginHyperlink to add an attribute that 
    ' references the referring page.
    Public Overrides Sub RenderBeginHyperlink( _
        ByVal writer As HtmlTextWriter, ByVal targetUrl As String, _
        ByVal encodeUrl As Boolean, ByVal softkeyLabel As String, _
        ByVal accessKey As String)
        Dim url As String
        ' Add the src attribute, if referring page URL is available.
        If Not (Page Is Nothing) Then
            If Not (Page.Request Is Nothing) Then
                If Not (Page.Request.Url Is Nothing) Then
                    url = Page.Request.Url.AbsoluteUri
                    If encodeUrl Then
                        url = HttpUtility.HtmlAttributeEncode(url)
                    End If
                    writer.AddAttribute("src", url)
                End If
            End If
        End If
        ' Render the accessKey attribute, if requested.
        If Not (accessKey Is Nothing) Then
            If accessKey.Length = 1 Then
                writer.AddAttribute("accessKey", accessKey)
            End If
        End If
        ' Add the href attribute, encode the URL if requested.
        If (encodeUrl) Then
            url = HttpUtility.HtmlAttributeEncode(targetUrl)
        Else
            url = targetUrl
        End If
        writer.AddAttribute("href", url)
        ' Render the hyperlink opening tag with the added attributes.
        writer.RenderBeginTag("a")
    End Sub
End Class
注解
该 PageAdapter 类是一个抽象类,它根据浏览器使用 (的标记语言(例如 HTML 或 XHTML) )定义的特定浏览器类来调整网页。 呈现行为中的大部分适应性可以封装在派生自 HtmlTextWriter 类的专用文本编写器类中,因此并不总是需要提供页面适配器。
派生页适配器的大多数成员都是从 Page 类或控件适配器调用的。 首先, Page 类或控件适配器会检测派生页适配器的存在,然后调用成员,或者在页面适配器不存在时提供功能。
类的成员 PageAdapter 提供以下功能:
- CacheVaryByHeaders属性CacheVaryByParams定义其他 HTTP 标头和 HTTP - GET以及- POST可用于更改缓存的参数。 在从 Page 类进行缓存初始化期间调用它们。
- 该方法 GetStatePersister 返回一个对象,该对象可用于保留页面的组合视图和控件状态。 如果存在派生页适配器, PageStatePersister 则从属性引用该属性。 
- 该方法 GetPostBackFormReference 提供可用于引用脚本中的表单的 DHTML 代码片段。 
- 如果页面处于回发状态,该方法 DeterminePostBackMode 将返回回发变量的集合。 如果存在派生页适配器,则由.NET Framework而不是Page.DeterminePostBackMode方法调用。 
- 如果存在派生的页面适配器,控件 RenderBeginHyperlink 适配器将使用这些和 RenderEndHyperlink 方法来呈现超链接。 
- 该方法 RenderPostBackEvent 呈现可以提交表单的超链接或回发客户端标记。 
- RegisterRadioButton单选按钮控件适配器使用和GetRadioButtonsByGroup方法引用单选按钮组中的其他RadioButton控件。 
- 该ClientState属性通过类的内部 - ClientState属性Page提供对对象的组合控件和视图状态Page的访问。
- 控件 TransformText 适配器使用此方法来执行特定于设备的文本转换。 
构造函数
| PageAdapter() | 初始化 PageAdapter 类的新实例。 | 
属性
| Browser | 获取对发出当前 HTTP 请求的客户端的浏览器功能的引用。(继承自 ControlAdapter) | 
| CacheVaryByHeaders | 获取其他 HTTP 标头的列表,对于已附加此派生的页面适配器的网页,缓存将随这些标头而改变。 | 
| CacheVaryByParams | 从 HTTP GET 和 POST 请求获得其他参数的列表,对于已附加此派生的页面适配器的网页,高速缓存将随这些参数而改变。 | 
| ClientState | 获取一个经过编码的字符串,其中包含已附加此派生的页面适配器的网页的视图和控件状态数据。 | 
| Control | 获取对附加了此控件适配器的控件的引用。(继承自 ControlAdapter) | 
| Page | 获取对与此适配器关联的控件所驻留的页的引用。(继承自 ControlAdapter) | 
| PageAdapter | 获取对关联控件所驻留的页的页适配器的引用。(继承自 ControlAdapter) |