Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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 system.design.dll)

public class LabelDesigner : TextControlDesigner
public class LabelDesigner extends TextControlDesigner
public class LabelDesigner extends TextControlDesigner
Not applicable.

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.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.SampleLabelDesigner))]
    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;

                try
                {
                    // 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);
                }
                finally
                {
                    // Restore the BorderStyle to its original setting.
                    sampleLabel.BorderStyle = oldBorderStyle;
                }
            }
            else
                // 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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft