Edit

Share via


HideDisabledControlAdapter Class

Definition

Provides rendering capabilities for the associated Web control to modify the default markup or behavior for a specific browser.

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
Inheritance
HideDisabledControlAdapter

Examples

The following code example shows how to extend the HideDisabledControlAdapter class to display a Label control in an enabled and disabled state. This example contains three parts:

  • An adapter derived from the HideDisabledControlAdapter class.

  • The .aspx file that incorporates the Label control and device-specific content.

  • A browser file to link the adapter to a device type.

The following code example demonstrates how to extend the HideDisabledControlAdapter class.

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

The following code example demonstrates how to declare a Label control with device-specific content.

<%@ 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>

The following code example shows how to link the Label control to the custom adapter for browsers running on Windows CE .NET.

Remarks

The HideDisabledControlAdapter class adapts the associated WebControl control to modify the default markup or behavior for a specific browser. You can extend the HideDisabledControlAdapter class to further customize rendering of the WebControl control.

Adapters are compiled .NET Framework components that take over one or more stages in the life cycle of a page or control. Extending the HideDisabledControlAdapter class will provide access to the life-cycle stages of the WebControl control. For more information, see Architectural Overview of Adaptive Control Behavior.

The initial request for an adapter causes the .NET Framework to search for a mapped adapter for the control given the characteristics of the requesting browser. Browser definition files are used by the HttpBrowserCapabilities class to identify the characteristics of the client browser and map the adapter to the browser type. For more information, see Architectural Overview of Adaptive Control Behavior.

Constructors

HideDisabledControlAdapter()

Initializes a new instance of the HideDisabledControlAdapter class.

Properties

Browser

Gets a reference to the browser capabilities of the client making the current HTTP request.

(Inherited from ControlAdapter)
Control

Gets a reference to the Web control to which this control adapter is attached.

(Inherited from WebControlAdapter)
IsEnabled

Gets a value indicating whether the Web control and all its parent controls are enabled.

(Inherited from WebControlAdapter)
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)
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)
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)
Render(HtmlTextWriter)

Writes the associated Web control to the output stream as HTML.

RenderBeginTag(HtmlTextWriter)

Creates the beginning tag for the Web control in the markup that is transmitted to the target browser.

(Inherited from WebControlAdapter)
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)
RenderContents(HtmlTextWriter)

Generates the target-specific inner markup for the Web control to which the control adapter is attached.

(Inherited from WebControlAdapter)
RenderEndTag(HtmlTextWriter)

Creates the ending tag for the Web control in the markup that is transmitted to the target browser.

(Inherited from WebControlAdapter)
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)

Applies to

See also