HideDisabledControlAdapter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供相關網頁控制項的渲染功能,以修改特定瀏覽器的預設標記或行為。
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 類別衍生而來的轉接器。
.aspx檔案,包含 Label 控制項和裝置專屬內容。
一個瀏覽器檔案,用來將轉接器連結到裝置類型。
以下程式碼範例示範如何擴充該 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 控制項連結到執行 CE .NET Windows 瀏覽器的自訂介面卡。
備註
該 HideDisabledControlAdapter 類別會調整相關 WebControl 控制項,以修改特定瀏覽器的預設標記或行為。 你可以擴充 HideDisabledControlAdapter 類別,進一步自訂控制的渲染 WebControl 。
介面卡是編譯後的 .NET Framework 元件,負責接管頁面或控制項生命週期中的一個或多個階段。 擴展 HideDisabledControlAdapter 類別將提供控制的生命週期階段 WebControl 存取權。 欲了解更多資訊,請參閱 《自適應控制行為架構概述》。
初始的介面卡請求會使 .NET Framework 根據請求瀏覽器的特性搜尋該控制的映射介面卡。 類別使用 HttpBrowserCapabilities 瀏覽器定義檔案來識別用戶端瀏覽器的特性,並將適配器映射到瀏覽器類型。 欲了解更多資訊,請參閱 《自適應控制行為架構概述》。
建構函式
| 名稱 | Description |
|---|---|
| HideDisabledControlAdapter() |
初始化 HideDisabledControlAdapter 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Browser |
會取得目前 HTTP 請求客戶端瀏覽器功能的參考。 (繼承來源 ControlAdapter) |
| Control |
會得到一個指向這個控制轉接器所連接的網頁控制的參考。 (繼承來源 WebControlAdapter) |
| IsEnabled |
會獲得一個值,表示網頁控制項及其所有父控制項是否已啟用。 (繼承來源 WebControlAdapter) |
| Page |
會取得指向該轉接器相關控制項所在頁面的參考。 (繼承來源 ControlAdapter) |
| PageAdapter |
會取得該頁面介面卡的參考,該頁面包含相關控制項所在。 (繼承來源 ControlAdapter) |