PageAdapter クラス
アセンブリ: System.Web (system.web.dll 内)


PageAdapter クラスは、ブラウザが使用するマークアップ言語 (HTML や XHTML など) で定義された、ブラウザの特定のクラスに対して Web ページを調整する抽象クラスです。表示動作の適応性の多くは、HtmlTextWriter クラスから派生した専用のテキスト ライタ クラスにカプセル化できるので、常にページ アダプタを用意する必要はありません。
派生ページ アダプタのほとんどのメンバは、Page クラスかコントロール アダプタから呼び出されます。Page クラスまたはコントロール アダプタは、最初に、派生ページ アダプタが存在するかどうかを検出し、そのメンバを呼び出します。ページ アダプタが存在しない場合は、機能を提供します。
PageAdapter クラスのプロパティは、次の機能を提供します。
-
CacheVaryByHeaders プロパティおよび CacheVaryByParams プロパティは、キャッシュを変更するために使用できる、追加の HTTP ヘッダーと HTTP の GET パラメータおよび POST パラメータを定義します。これらは、キャッシュの初期化中に Page クラスから呼び出されます。
-
GetStatePersister メソッドは、ビューとページのコントロール状態の組み合わせを永続化するために使用できるオブジェクトを返します。これは、派生ページ アダプタが存在する場合に、PageStatePersister プロパティから参照されます。
-
GetPostBackFormReference メソッドは、スクリプトでフォームを参照するために使用できる DHTML のコード片を提供します。
-
DeterminePostBackMode メソッドは、ページがポストバック中の場合、ポストバック変数のコレクションを返します。派生ページ アダプタが存在する場合、これは、Page.DeterminePostBackMode メソッドからではなく、.NET Framework によって呼び出されます。
-
RenderBeginHyperlink メソッドおよび RenderEndHyperlink メソッドは、派生ページ アダプタが存在する場合に、コントロール アダプタによってハイパーリンクを表示するために使用されます。
-
RenderPostBackEvent メソッドは、フォームを送信できるハイパーリンクまたはポストバック クライアント タグを表示します。
-
RegisterRadioButton メソッドおよび GetRadioButtonsByGroup メソッドは、オプション ボタン コントロール アダプタによって、オプション ボタン グループ内の他の RadioButton コントロールを参照するために使用されます。
-
ClientState プロパティは、Page クラスの内部プロパティである ClientState を通じて、コントロールと Page オブジェクトのビューステートの組み合わせにアクセスできるようにします。
-
TransformText メソッドは、コントロール アダプタによって、デバイス固有のテキスト変換を実行するために使用されます。

PageAdapter クラスから CustomPageAdapter という名前のクラスを派生させ、RenderBeginHyperlink メソッドをオーバーライドする方法を次のコード例に示します。RenderBeginHyperlink メソッドは、src という名前の属性をハイパーリンクに追加します。これには、現在のページへの参照が含まれます。CustomPageAdapter が割り当てられたページで表示されるすべてのハイパーリンクに、src 属性が使用されます。
Imports System Imports System.IO Imports System.Web Imports System.Web.UI Imports System.Web.UI.Adapters Imports Microsoft.VisualBasic ' 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 ' RenderBeginHyperlink End Class ' CustomPageAdapter
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" ); } }
import System.*; import System.IO.*; import System.Web.*; import System.Web.UI.*; import System.Web.UI.Adapters.*; // A derived PageAdapter class. public class CustomPageAdapter extends PageAdapter { // Override RenderBeginHyperlink to add an attribute that // references the referring page. public void RenderBeginHyperlink(HtmlTextWriter writer, String targetUrl, boolean encodeUrl, String softkeyLabel, String accessKey) { String url = null; // Add the src attribute, if referring page URL is available. if (this.get_Page() != null && this.get_Page().get_Request() != null && this.get_Page().get_Request().get_Url() != null) { url = this.get_Page().get_Request().get_Url().get_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"); } //RenderBeginHyperlink } //CustomPageAdapter


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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- PageAdapter クラスのページへのリンク