PageAdapter Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- Inheritance
Examples
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" );
}
}
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
Remarks
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
andPOST
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.
Constructors
PageAdapter() |
Initializes a new instance of the PageAdapter class. |
Properties
Browser |
Gets a reference to the browser capabilities of the client making the current HTTP request. (Inherited from ControlAdapter) |
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. |
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. |
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 |
Gets a reference to the control to which this control adapter is attached. (Inherited from ControlAdapter) |
Page |
Gets a reference to the page where the control associated with this adapter resides. (Inherited from ControlAdapter) |
PageAdapter |
Gets a reference to the page adapter for the page where the associated control resides. (Inherited from ControlAdapter) |
Methods
BeginRender(HtmlTextWriter) |
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) |
CreateChildControls() |
Creates the target-specific child controls for a composite control. (Inherited from ControlAdapter) |
DeterminePostBackMode() |
Determines whether the Web page is in postback and returns a name/value collection of the postback variables. |
DeterminePostBackModeUnvalidated() |
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) |
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) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetPostBackFormReference(String) |
Returns a DHTML code fragment that the client browser can use to reference the form on the page that was posted. |
GetRadioButtonsByGroup(String) |
Retrieves a collection of radio button controls specified by |
GetStatePersister() |
Returns an object that is used by the Web page to maintain the control and view states. |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
LoadAdapterControlState(Object) |
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) |
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() |
Creates a shallow copy of the current Object. (Inherited from Object) |
OnInit(EventArgs) |
Overrides the OnInit(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnLoad(EventArgs) |
Overrides the OnLoad(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnPreRender(EventArgs) |
Overrides the OnPreRender(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnUnload(EventArgs) |
Overrides the OnUnload(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
RegisterRadioButton(RadioButton) |
Adds a radio button control to the collection for a specified radio button group. |
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) |
Renders an opening hyperlink tag that includes the target URL to the response stream. |
RenderBeginHyperlink(HtmlTextWriter, String, Boolean, String, String) |
Renders an opening hyperlink tag that includes the target URL and an access key to the response stream. |
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) |
Renders a closing hyperlink tag to the response stream. |
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) |
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) |
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() |
Saves control state information for the control adapter. (Inherited from ControlAdapter) |
SaveAdapterViewState() |
Saves view state information for the control adapter. (Inherited from ControlAdapter) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
TransformText(String) |
Transforms text for the target browser. |
Applies to
See also
Зворотний зв’язок
https://aka.ms/ContentUserFeedback.
Очікується незабаром: протягом 2024 року ми будемо припиняти використання механізму реєстрації проблем у GitHub для зворотного зв’язку щодо вмісту й замінювати його новою системою зворотного зв’язку. Докладніше:Надіслати й переглянути відгук про