ControlDesigner Class

Provides a base control designer class for extending the design-mode behavior of a Web server control.

Namespace: System.Web.UI.Design
Assembly: System.Design (in

public class ControlDesigner : HtmlControlDesigner
public class ControlDesigner extends HtmlControlDesigner
public class ControlDesigner extends HtmlControlDesigner

The ControlDesigner class provides a base control designer class that can be inherited from and extended to provide design-time support for a Web server control in a design host, such as Visual Studio 2005.

The object model for working with design-time rendering is improved over earlier versions, with the following new base classes to provide access to the simplified object model:

Automatic Formatting

You can create a variety of automatic and pre-defined formats that can simplify the process of page developers who are applying complex style changes to custom Web server controls. For example, the TableDesigner control, which derives from the ControlDesigner class, provides many automatic formats from which to choose. To implement and provide automatic formatting in your custom controls, use the following features:

Action Lists (Smart Tags)

Action lists are menus of important or widely used tasks that a page developer who uses a control can perform in a design-time user interface (UI), such as Visual Studio 2005. For example, the design-time view of your control could provide a menu of available tasks. This includes a task to format the control automatically. To learn about action lists, start with the following features:

Control Designer Regions

Regions are editable areas in the design-time view of a Web server control. This feature offers WYSIWYG-like editing of the template content, inner controls, and properties at design time. You can have the control designer create controls in regions or you can use the Toolbox to drag and drop controls into regions. Regions are managed with the following features:


The model for creating a UI for design-time editing of templated controls, such as the GridView control, has been greatly improved from earlier versions. You can create complex custom controls that include templates for various parts of the control, and your custom control designer can help page developers who are modifying templates with the following features:

Design-Time Rendering

The ControlDesigner class has the following methods to support design-time rendering of the Web server control. Most of these methods are the same as in earlier versions:

The following code example demonstrates how to create a simple designer class that derives from the ControlDesigner class. This control designer supports a custom TextControl class and provides a command to change the text size of a control at design time. The control designer is associated with the control by specifying the control designer in a DesignerAttribute object declaration on the TextControl class. The key to persisting property changes from the control designer to the HTML markup is found in the ToggleTextSize method of the custom ActionList class.

To try the example, add a reference to the System.Design.dll assembly and compile the code.

using System;
using System.Web.UI;
using System.Drawing;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace ASPNet.Design.Samples.CS
    // Simple text Web control renders a text string.
    // This control is associated with the TextSizeWebControlDesigner.
    ToolboxData("<{0}:TextControl runat=\"server\"></{0}:TextControl>")]
    public class TextControl : Label
        private bool _largeText = true;

        // Constructor
        public TextControl()
            Text = "Test Phrase";

        // Determines whether the text is large or small
        [Bindable(true), Category("Appearance"), DefaultValue("true")]
        public bool LargeText
            get { return _largeText; }
                _largeText = value;

        // Applies the LargeText property to the control
        private void SetSize()
            if (LargeText)
                this.Font.Size = FontUnit.XLarge;
                this.Font.Size = FontUnit.Small;

    // This control designer offers DesignerActionList commands
    // that can alter the design time html of the associated control.
    public class TextSizeWebControlDesigner : ControlDesigner
        private DesignerActionListCollection _actionLists = null;

        // Do not allow direct resizing of the control
        public override bool AllowResize
            get { return false; }

        // Return a custom ActionList collection
        public override DesignerActionListCollection ActionLists
                if (_actionLists == null)
                    _actionLists = new DesignerActionListCollection();

                    // Add a custom DesignerActionList
                    _actionLists.Add(new ActionList(this));
                return _actionLists;

        public class ActionList : DesignerActionList
            private TextSizeWebControlDesigner _parent;
            private DesignerActionItemCollection _items;

            // Constructor
            public ActionList(TextSizeWebControlDesigner parent)
                : base(parent.Component)
                _parent = parent;


            // Create the ActionItem collection and add one command
            public override DesignerActionItemCollection GetSortedActionItems()
                if (_items == null)
                    _items = new DesignerActionItemCollection();
                    _items.Add(new DesignerActionMethodItem(this, "ToggleLargeText", "Toggle Text Size", true));
                return _items;

            // ActionList command to change the text size
            private void ToggleLargeText()
                // Get a reference to the parent designer's associated control
                TextControl ctl = (TextControl)_parent.Component;

                // Get a reference to the control's LargeText property
                PropertyDescriptor propDesc = TypeDescriptor.GetProperties(ctl)["LargeText"];

                // Get the current value of the property
                bool v = (bool)propDesc.GetValue(ctl);

                // Toggle the property value
                propDesc.SetValue(ctl, !v);
...<%@ Page Language="C#" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="ASPNet.Design.Samples.CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">


<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <aspSample:TextControl ID=TextControl1 runat="server">


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 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, 1.1, 1.0