PageAdapter PageAdapter PageAdapter PageAdapter Class

定義

針對特定的瀏覽器來配置網頁,並提供基底類別,而所有頁面配置器都會直接或間接繼承自此基底類別。Adapts a Web page for a specific browser and provides the base class from which all page adapters inherit, directly or indirectly.

public ref class PageAdapter abstract : System::Web::UI::Adapters::ControlAdapter
public abstract class PageAdapter : System.Web.UI.Adapters.ControlAdapter
type PageAdapter = class
    inherit ControlAdapter
Public MustInherit Class PageAdapter
Inherits ControlAdapter
繼承

範例

下列程式碼範例示範如何CustomPageAdapter PageAdapter從類別衍生名為的類別, 並覆寫RenderBeginHyperlink方法。The following code example demonstrates how to derive a class named CustomPageAdapter from the PageAdapter class and override the RenderBeginHyperlink method. 方法會將名src為的屬性加入至超連結, 其中包含目前頁面的參考。 RenderBeginHyperlinkThe RenderBeginHyperlink method adds an attribute named src to a hyperlink, which contains a reference to the current page. 在附加的頁面CustomPageAdapter中呈現的所有超連結都會src有屬性。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" );
    }
}
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 ' CustomPageAdapter

備註

PageAdapter類別是一種抽象類別, 可調整特定瀏覽器類別的網頁, 並由瀏覽器所使用的標記語言 (例如 HTML 或 XHTML) 所定義。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). 轉譯行為中的許多適應性可以封裝在衍生自HtmlTextWriter類別的特製化文字寫入器類別中, 因此不一定要提供分頁介面卡。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.

衍生頁面介面卡的大部分成員都是從Page類別或控制介面卡呼叫。Most members of derived page adapters are called from the Page class or from control adapters. 首先, Page類別或控制介面卡會偵測衍生的頁面介面卡是否存在, 然後呼叫該成員, 如果頁面介面卡不存在, 則會提供功能。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.

PageAdapter類別的成員提供下列功能:The members of the PageAdapter class provide the following functionality:

建構函式

PageAdapter() PageAdapter() PageAdapter() PageAdapter()

初始化 PageAdapter 類別的新執行個體。Initializes a new instance of the PageAdapter class.

屬性

Browser Browser Browser Browser

取得對用戶端瀏覽器功能的參考 (此用戶端是發出目前 HTTP 要求的用戶端)。Gets a reference to the browser capabilities of the client making the current HTTP request.

(Inherited from ControlAdapter)
CacheVaryByHeaders CacheVaryByHeaders CacheVaryByHeaders CacheVaryByHeaders

取得其他 HTTP 標頭的清單,而且會根據此清單為附加此衍生頁面配置器的網頁變更快取。Gets a list of additional HTTP headers by which caching is varied for the Web page to which this derived page adapter is attached.

CacheVaryByParams CacheVaryByParams CacheVaryByParams CacheVaryByParams

從 HTTP GET 和 POST 要求取得其他參數的清單,而且會根據此清單為附加此衍生頁面配置器的網頁變更快取。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.

ClientState ClientState ClientState 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.

Control Control Control Control

取得控制項的參考 (指控制項配置器附加的控制項)。Gets a reference to the control to which this control adapter is attached.

(Inherited from ControlAdapter)
Page Page Page Page

取得對頁面的參考 (與此配置器相關聯的控制項便存在於此頁面中)。Gets a reference to the page where the control associated with this adapter resides.

(Inherited from ControlAdapter)
PageAdapter PageAdapter PageAdapter PageAdapter

取得對此頁的頁面配置器的參考 (關聯的控制項便存在於此頁面中)。Gets a reference to the page adapter for the page where the associated control resides.

(Inherited from ControlAdapter)

方法

BeginRender(HtmlTextWriter) BeginRender(HtmlTextWriter) BeginRender(HtmlTextWriter) BeginRender(HtmlTextWriter)

在呈現控制項之前呼叫。Called prior to the rendering of a control. 在衍生的配置器類別中,產生特定目標所需的開頭標記 (而非 HTML 瀏覽器所需)。In a derived adapter class, generates opening tags that are required by a specific target but not needed by HTML browsers.

(Inherited from ControlAdapter)
CreateChildControls() CreateChildControls() CreateChildControls() CreateChildControls()

為複合控制項建立特定目標的子控制項。Creates the target-specific child controls for a composite control.

(Inherited from ControlAdapter)
DeterminePostBackMode() DeterminePostBackMode() DeterminePostBackMode() DeterminePostBackMode()

判斷網頁是否在回傳中,然後傳回回傳變數的名稱/值組合。Determines whether the Web page is in postback and returns a name/value collection of the postback variables.

DeterminePostBackModeUnvalidated() DeterminePostBackModeUnvalidated() DeterminePostBackModeUnvalidated() DeterminePostBackModeUnvalidated()

傳回使用 POST 或 GET 命令發佈至網頁中的資料名稱-值集合,但不對要求執行 ASP.NET 要求驗證。Returns a name-value collection of data that was posted to the page using either a POST or a GET command, without performing ASP.NET request validation on the request.

EndRender(HtmlTextWriter) EndRender(HtmlTextWriter) EndRender(HtmlTextWriter) EndRender(HtmlTextWriter)

在呈現控制項之後呼叫。Called after the rendering of a control. 在衍生的配置器類別中,產生特定目標所需的結尾標記 (而非 HTML 瀏覽器所需)。In a derived adapter class, generates closing tags that are required by a specific target but not needed by HTML browsers.

(Inherited from ControlAdapter)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetPostBackFormReference(String) GetPostBackFormReference(String) GetPostBackFormReference(String) GetPostBackFormReference(String)

傳回 DHTML 程式碼片段,用戶端瀏覽器可利用此程式碼片段參考被張貼之頁面上的表單。Returns a DHTML code fragment that the client browser can use to reference the form on the page that was posted.

GetRadioButtonsByGroup(String) GetRadioButtonsByGroup(String) GetRadioButtonsByGroup(String) GetRadioButtonsByGroup(String)

擷取由 groupName 所指定的選項按鈕控制項集合。Retrieves a collection of radio button controls specified by groupName.

GetStatePersister() GetStatePersister() GetStatePersister() GetStatePersister()

傳回網頁所使用的物件,以維護控制項和檢視狀態。Returns an object that is used by the Web page to maintain the control and view states.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
LoadAdapterControlState(Object) LoadAdapterControlState(Object) LoadAdapterControlState(Object) LoadAdapterControlState(Object)

載入之前在對頁面發出要求的期間由 SaveAdapterControlState() 所儲存的配置器控制項狀態資訊 (與此控制項配置器相關聯的控制項便存在於此頁面中)。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)
LoadAdapterViewState(Object) LoadAdapterViewState(Object) LoadAdapterViewState(Object) LoadAdapterViewState(Object)

載入之前在對頁面發出要求的期間由 SaveAdapterViewState() 所儲存的配置器檢視狀態資訊 (與此控制項配置器相關聯的控制項便存在於此頁面中)。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)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnInit(EventArgs) OnInit(EventArgs) OnInit(EventArgs) OnInit(EventArgs)

為關聯控制項覆寫 OnInit(EventArgs) 方法。Overrides the OnInit(EventArgs) method for the associated control.

(Inherited from ControlAdapter)
OnLoad(EventArgs) OnLoad(EventArgs) OnLoad(EventArgs) OnLoad(EventArgs)

為關聯控制項覆寫 OnLoad(EventArgs) 方法。Overrides the OnLoad(EventArgs) method for the associated control.

(Inherited from ControlAdapter)
OnPreRender(EventArgs) OnPreRender(EventArgs) OnPreRender(EventArgs) OnPreRender(EventArgs)

為關聯控制項覆寫 OnPreRender(EventArgs) 方法。Overrides the OnPreRender(EventArgs) method for the associated control.

(Inherited from ControlAdapter)
OnUnload(EventArgs) OnUnload(EventArgs) OnUnload(EventArgs) OnUnload(EventArgs)

為關聯控制項覆寫 OnUnload(EventArgs) 方法。Overrides the OnUnload(EventArgs) method for the associated control.

(Inherited from ControlAdapter)
RegisterRadioButton(RadioButton) RegisterRadioButton(RadioButton) RegisterRadioButton(RadioButton) RegisterRadioButton(RadioButton)

將選項按鈕控制項加入指定選項按鈕群組的集合中。Adds a radio button control to the collection for a specified radio button group.

Render(HtmlTextWriter) Render(HtmlTextWriter) Render(HtmlTextWriter) Render(HtmlTextWriter)

為附加控制項配接器的控制項,產生目標特定的標記。Generates the target-specific markup for the control to which the control adapter is attached.

(Inherited from ControlAdapter)
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String)

呈現開頭的超連結標記到回應資料流,其中包含的目標 URL。Renders an opening hyperlink tag that includes the target URL to the response stream.

RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String)

呈現開頭的超連結標記到回應資料流,其中包含目標 URL 和便捷鍵 (Access Key)。Renders an opening hyperlink tag that includes the target URL and an access key to the response stream.

RenderChildren(HtmlTextWriter) RenderChildren(HtmlTextWriter) RenderChildren(HtmlTextWriter) RenderChildren(HtmlTextWriter)

為複合控制項中的子控制項產生特定目標的標記 (控制項配置器會附加至此複合控制項)。Generates the target-specific markup for the child controls in a composite control to which the control adapter is attached.

(Inherited from ControlAdapter)
RenderEndHyperlink(HtmlTextWriter) RenderEndHyperlink(HtmlTextWriter) RenderEndHyperlink(HtmlTextWriter) RenderEndHyperlink(HtmlTextWriter)

將結尾的超連結標記呈現至回應資料流中。Renders a closing hyperlink tag to the response stream.

RenderPostBackEvent(HtmlTextWriter, String, String, String, String) RenderPostBackEvent(HtmlTextWriter, String, String, String, String) RenderPostBackEvent(HtmlTextWriter, String, String, String, String) 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.

RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String) RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String) RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String) 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.

RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String, Boolean) RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String, Boolean) RenderPostBackEvent(HtmlTextWriter, String, String, String, String, String, String, Boolean) 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.

SaveAdapterControlState() SaveAdapterControlState() SaveAdapterControlState() SaveAdapterControlState()

儲存控制項配置器的控制項狀態資訊。Saves control state information for the control adapter.

(Inherited from ControlAdapter)
SaveAdapterViewState() SaveAdapterViewState() SaveAdapterViewState() SaveAdapterViewState()

儲存控制項配置器的檢視狀態資訊。Saves view state information for the control adapter.

(Inherited from ControlAdapter)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TransformText(String) TransformText(String) TransformText(String) TransformText(String)

轉換目標瀏覽器的文字。Transforms text for the target browser.

適用於

另請參閱