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)

[SupportsPreviewControlAttribute(true)]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class LabelDesigner : 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.
    [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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft