HideDisabledControlAdapter 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为关联的 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 类以显示 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) |