LabelDesigner Class

Provides design-time support in a visual designer for the Label Web server control.

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

public class LabelDesigner : TextControlDesigner
public class LabelDesigner extends TextControlDesigner
public class LabelDesigner extends TextControlDesigner

The Label control allows text to be displayed programmatically on a Web page.

In a visual designer, when you switch from Source to Design view, the markup source code that describes a Label control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to the markup source code and edited into the markup for the Web page. The LabelDesigner class provides design-time support for the Label control.

The OnComponentChanged method is called when there is a change to the associated Label control.

The following code example shows how to derive the SampleLabel control from the Label control, and applies a DesignerAttribute attribute on the SampleLabel control to associate it with the SampleLabelDesigner class.

The code example also derives the SampleLabelDesigner from the LabelDesigner class. It overrides the GetDesignTimeHtml method to set the BorderStyle property to Dashed, if the original BorderStyle was the NotSet or None value. This improves the visibility of the associated control at design time.

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
    // The SampleLabel is a copy of the Label.
        Level = AspNetHostingPermissionLevel.Minimal)]
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class SampleLabel : Label
    } // SampleLabel

    // Override members of the LabelDesigner.
    public class SampleLabelDesigner : LabelDesigner
        // Generate the design-time markup.
        public override string GetDesignTimeHtml()
            // Make the control more visible in the designer.  If the border 
            // style is None or NotSet, change the border to a dashed line. 
            SampleLabel sampleLabel = (SampleLabel)Component;
            string designTimeMarkup = null;

            // Check if the border style should be changed.
            if (sampleLabel.BorderStyle == BorderStyle.NotSet ||
                sampleLabel.BorderStyle == BorderStyle.None)
                BorderStyle oldBorderStyle = sampleLabel.BorderStyle;

                    // Set the design-time BorderStyle.
                    sampleLabel.BorderStyle = BorderStyle.Dashed;

                    // Call the base method to generate the markup.
                    designTimeMarkup = base.GetDesignTimeHtml();
                catch (Exception ex)
                    // If an exception occurs, generate an error message.
                    designTimeMarkup = GetErrorDesignTimeHtml(ex);
                    // Restore the BorderStyle to its original setting.
                    sampleLabel.BorderStyle = oldBorderStyle;
                // Call the base method to generate the markup.
                designTimeMarkup = base.GetDesignTimeHtml();

            return designTimeMarkup;
        } // GetDesignTimeHtml
    } // SampleLabelDesigner
} // Examples.CS.WebControls.Design

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