Export (0) Print
Expand All

HideDisabledControlAdapter Class

Note: This class is new in the .NET Framework version 2.0.

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

Namespace: System.Web.UI.WebControls.Adapters
Assembly: System.Web (in system.web.dll)

public class HideDisabledControlAdapter : WebControlAdapter
public class HideDisabledControlAdapter extends WebControlAdapter
public class HideDisabledControlAdapter extends WebControlAdapter

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.

For a description of the adaptive rendering architecture of ASP.NET and a step-by-step walkthrough that shows how to implement a control adapter and map it to a control, see "Authoring ASP.NET Server Control Adapters: An Introduction" in the MSDN Library at http://msdn.microsoft.com/library.

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);
        }
    }
}

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

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

<html>
<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 bgcolor=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">
            <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.

<browsers>
    <browser refID="WinCE">
        <controlAdapters>
            <adapter controlType="System.Web.UI.WebControls.Label" 
                adapterType="Contoso.HideDisabledControlContosoAdapter" />
        </controlAdapters>
    </browser>
    <browser refID="IE">
        <controlAdapters>
            <adapter controlType="System.Web.UI.WebControls.Label" 
                adapterType="Contoso.HideDisabledControlContosoAdapter" />
        </controlAdapters>
    </browser>
</browsers>

  • AspNetHostingPermission  for verifying at compilation time that the immediate caller has permission to call into the HideDisabledControlAdapter class. Associated enumeration: Minimal
  • AspNetHostingPermission  for verifying that any class derived from the HideDisabledControlAdapter class has at least the Minimal trust level. Associated enumeration: Minimal

System.Object
   System.Web.UI.Adapters.ControlAdapter
     System.Web.UI.WebControls.Adapters.WebControlAdapter
      System.Web.UI.WebControls.Adapters.HideDisabledControlAdapter

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft