HideDisabledControlAdapter 类

定义

为关联的 Web 控件提供呈现功能,以修改特定浏览器的默认标记或行为。

public ref class HideDisabledControlAdapter : System::Web::UI::WebControls::Adapters::WebControlAdapter
public class HideDisabledControlAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
type HideDisabledControlAdapter = class
    inherit WebControlAdapter
Public Class HideDisabledControlAdapter
Inherits WebControlAdapter
继承
HideDisabledControlAdapter

示例

下面的代码示例演示如何扩展 HideDisabledControlAdapter 类以显示 Label 处于启用和禁用状态的控件。 此示例包含三个部分:

  • 派生自类的 HideDisabledControlAdapter 适配器。

  • 包含 Label 控件和设备特定内容的.aspx文件。

  • 用于将适配器链接到设备类型的浏览器文件。

下面的代码示例演示如何扩展 HideDisabledControlAdapter 类。

using System;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;

namespace Contoso
{
    [AspNetHostingPermission(
        SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(
        SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class HideDisabledControlContosoAdapter:
        System.Web.UI.WebControls.Adapters.HideDisabledControlAdapter
    {
        // Link the Label control to the adapter.
        protected new System.Web.UI.WebControls.Label Control
        {
            get
            {
                return (System.Web.UI.WebControls.Label)base.Control;
            }
        }

        // Do not render the Contoso controls if Enabled is false.
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (Control.ID.StartsWith("Contoso"))
            {
                if (!Control.Enabled)
                {
                    return;
                }
            }

            base.Render(writer);
        }
    }
}
Imports System.Web
Imports System.Web.UI
Imports System.Security.Permissions

Namespace Contoso
    <AspNetHostingPermission( _
        SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission( _
        SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class HideDisabledControlContosoAdapter
        Inherits System.Web.UI.WebControls.Adapters.HideDisabledControlAdapter
    
        Protected Overloads ReadOnly Property Control() As _
            System.Web.UI.WebControls.Label
            Get
                Return CType( _
                    MyBase.Control, _
                    System.Web.UI.WebControls.Label)
            End Get
        End Property

        ' Do not render the control if Enabled is false.
        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            If (Control.ID.StartsWith("Contoso")) Then
                If (Not Control.Enabled) Then
                    Return
                End If
            End If

            MyBase.Render(writer)
        End Sub
    End Class
End Namespace

下面的代码示例演示如何使用特定于设备的内容声明 Label 控件。

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>HideDisabledControl Adapter</title>
    <script runat="server">
        void ServerButtonClick(Object source, EventArgs args)
        {
            if (Button1.Text == "Enable Label")
            {
                ContosoLabel1.Enabled = true;
                Button1.Text = "Disable Label";
                messageLabel.Text = "The label is <b>En</b>abled";
            }
            else
            {
                ContosoLabel1.Enabled = false;
                Button1.Text = "Enable Label";
                messageLabel.Text = "The label is <b>dis</b>abled";
            }
        }
    </script>
</head>
<body style="background-color:silver">
    <form id="Form1" runat="server">
        <asp:Label id="ContosoLabel1"             
            text="Contoso Label" 
            WinCE:text="CE Label"
            BorderWidth="3" 
            BorderStyle="Inset"
            style="FONT-SIZE: xx-small"
            runat="server">
            </asp:Label>
        <br />
        <asp:Button id="Button1" 
            text="Disable Label"
            OnClick="ServerButtonClick" 
            runat="server" />
        <br />    
        <asp:Label id="messageLabel" 
            runat="server" 
            style="FONT-SIZE: xx-small"
            AssociatedControlID="Button1">
            <i>Select the button to disable the label.</i>
        </asp:Label>
    </form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>HideDisabledControl Adapter</title>
    <script runat="server">
        Sub ServerButtonClick(ByVal source As Object, ByVal args As EventArgs)
            If (Button1.Text.Equals("Enable Label")) Then
                ContosoLabel1.Enabled = True
                Button1.Text = "Disable Label"
                messageLabel.Text = "The label is <b>En</b>abled"
            Else
                ContosoLabel1.Enabled = False
                Button1.Text = "Enable Label"
                messageLabel.Text = "The label is <b>dis</b>abled"
            End If
        End Sub
    </script>
</head>
<body style="background-color:silver">
    <form id="Form1" runat="server">
        <asp:Label id="ContosoLabel1"             
            text="Contoso Label" 
            WinCE:text="CE Label"
            BorderWidth="3" 
            BorderStyle="Inset"
            style="FONT-SIZE: xx-small"
            runat="server">
            </asp:Label>
        <br />
        <asp:Button id="Button1" 
            text="Disable Label"
            OnClick="ServerButtonClick" 
            runat="server" />
        <br />    
        <asp:Label id="messageLabel" 
            runat="server" 
            style="FONT-SIZE: xx-small"
            AssociatedControlID="Button1">
            <i>Select the button to disable the label.</i>
        </asp:Label>
    </form>
</body>
</html>

下面的代码示例演示如何将 Label 控件链接到在 WINDOWS CE .NET 上运行的浏览器的自定义适配器。

注解

HideDisabledControlAdapter 类调整关联的 WebControl 控件以修改特定浏览器的默认标记或行为。 可以扩展 HideDisabledControlAdapter 类以进一步自定义控件的 WebControl 呈现。

适配器.NET框架组件编译,这些组件接管页面或控件生命周期中的一个或多个阶段。 HideDisabledControlAdapter扩展类将提供对控件生命周期阶段WebControl的访问权限。 有关详细信息,请参阅 自适应控制行为的体系结构概述

适配器的初始请求会导致 .NET Framework 根据请求浏览器的特征搜索控件的映射适配器。 类使用 HttpBrowserCapabilities 浏览器定义文件来标识客户端浏览器的特征,并将适配器映射到浏览器类型。 有关详细信息,请参阅 自适应控制行为的体系结构概述

构造函数

名称 说明
HideDisabledControlAdapter()

初始化 HideDisabledControlAdapter 类的新实例。

属性

名称 说明
Browser

获取对发出当前 HTTP 请求的客户端的浏览器功能的引用。

(继承自 ControlAdapter)
Control

获取对此控件适配器所附加到的 Web 控件的引用。

(继承自 WebControlAdapter)
IsEnabled

获取一个值,该值指示是否启用 Web 控件及其所有父控件。

(继承自 WebControlAdapter)
Page

获取对与此适配器关联的控件所在的页面的引用。

(继承自 ControlAdapter)
PageAdapter

获取对关联控件所在的页面的页面适配器的引用。

(继承自 ControlAdapter)

方法

名称 说明
BeginRender(HtmlTextWriter)

在呈现控件之前调用。 在派生适配器类中,生成特定目标所需的打开标记,但 HTML 浏览器不需要这些标记。

(继承自 ControlAdapter)
CreateChildControls()

为复合控件创建特定于目标的子控件。

(继承自 ControlAdapter)
EndRender(HtmlTextWriter)

在控件呈现后调用。 在派生适配器类中,生成特定目标所需的结束标记,但 HTML 浏览器不需要这些标记。

(继承自 ControlAdapter)
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
LoadAdapterControlState(Object)

加载在上一个请求中保存 SaveAdapterControlState() 的适配器控件状态信息,该信息指向与此控件适配器关联的控件所在的页面。

(继承自 ControlAdapter)
LoadAdapterViewState(Object)

加载在上一个请求中保存 SaveAdapterViewState() 的适配器视图状态信息,该信息指向与此控件适配器关联的控件所在的页面。

(继承自 ControlAdapter)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnInit(EventArgs)

OnInit(EventArgs)重写关联控件的方法。

(继承自 ControlAdapter)
OnLoad(EventArgs)

OnLoad(EventArgs)重写关联控件的方法。

(继承自 ControlAdapter)
OnPreRender(EventArgs)

OnPreRender(EventArgs)重写关联控件的方法。

(继承自 ControlAdapter)
OnUnload(EventArgs)

OnUnload(EventArgs)重写关联控件的方法。

(继承自 ControlAdapter)
Render(HtmlTextWriter)

将关联的 Web 控件作为 HTML 写入输出流。

RenderBeginTag(HtmlTextWriter)

在传输到目标浏览器的标记中为 Web 控件创建起始标记。

(继承自 WebControlAdapter)
RenderChildren(HtmlTextWriter)

为附加控件适配器的复合控件中的子控件生成特定于目标的标记。

(继承自 ControlAdapter)
RenderContents(HtmlTextWriter)

为附加控件适配器的 Web 控件生成特定于目标的内部标记。

(继承自 WebControlAdapter)
RenderEndTag(HtmlTextWriter)

在传输到目标浏览器的标记中为 Web 控件创建结束标记。

(继承自 WebControlAdapter)
SaveAdapterControlState()

保存控件适配器的控件状态信息。

(继承自 ControlAdapter)
SaveAdapterViewState()

保存控件适配器的视图状态信息。

(继承自 ControlAdapter)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅