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 Framework元件,這些元件會接管頁面或控制項生命週期中的一或多個階段。 HideDisabledControlAdapter擴充 類別會提供控制項生命週期階段的 WebControl 存取權。 如需詳細資訊,請參閱 自適性控制行為的架構概觀。
介面卡的初始要求會導致.NET Framework在要求瀏覽器的特性下,搜尋控制項的對應介面卡。 類別會使用 HttpBrowserCapabilities 瀏覽器定義檔案來識別用戶端瀏覽器的特性,並將配接器對應至瀏覽器類型。 如需詳細資訊,請參閱 自適性控制行為的架構概觀。
建構函式
HideDisabledControlAdapter() |
初始化 HideDisabledControlAdapter 類別的新執行個體。 |
屬性
Browser |
取得對用戶端瀏覽器功能的參考 (此用戶端是發出目前 HTTP 要求的用戶端)。 (繼承來源 ControlAdapter) |
Control |
取得附加這個控制項配置器的 Web 控制項的參考。 (繼承來源 WebControlAdapter) |
IsEnabled |
取得值,表示 Web 控制器及其所有父控制項是否都已啟用。 (繼承來源 WebControlAdapter) |
Page |
取得對頁面的參考 (與此配置器相關聯的控制項便存在於此頁面中)。 (繼承來源 ControlAdapter) |
PageAdapter |
取得對此頁的頁面配置器的參考 (關聯的控制項便存在於此頁面中)。 (繼承來源 ControlAdapter) |
方法
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應