HyperLinkDesigner Class

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

Namespace: System.Web.UI.Design.WebControls
Assembly: System.Design (in system.design.dll)

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

The HyperLink control creates a link for the client browser to navigate to another Web page.

In a visual designer, when you switch from Source to Design view, the markup source code that describes a HyperLink 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 HyperLinkDesigner class provides design-time support for the HyperLink control.

The GetDesignTimeHtml method returns the markup that is used to render the associated HyperLink control at design time. The OnComponentChanged method is called when there is a change to the associated control.

This section contains two code examples. The first one demonstrates how to derive a class from the HyperLinkDesigner class, override a method, and supply a property value. The second one demonstrates how to derive a control from the HyperLink control and apply an attribute on the derived control.

The following code example shows how to derive a CustomHyperLinkDesigner class from the HyperLinkDesigner class. It overrides the GetDesignTimeHtml method to supply a default value for the Text property if the original value for the Text is an empty string (""). This ensures that the associated control will be visible at design time.

// Derive the CustomHyperLinkDesigner from the HyperLinkDesigner.
public class CustomHyperLinkDesigner : HyperLinkDesigner
    // Override the GetDesignTimeHtml to set the CustomHyperLink Text 
    // property so that it displays at design time.
    public override string GetDesignTimeHtml()
        CustomHyperLink hype = (CustomHyperLink)Component;
        string designTimeMarkup = null;

        // Save the original Text and note if it is empty.
        string text = hype.Text;
        bool noText = (text.Trim().Length == 0);

            // If the Text is empty, supply a default value.
            if (noText)
                hype.Text = "Click here.";

            // Call the base method to generate the markup.
            designTimeMarkup = base.GetDesignTimeHtml();
        catch (Exception ex)
            // If an error occurs, generate the markup for an error message.
            designTimeMarkup = GetErrorDesignTimeHtml(ex);
            // Restore the original value of the Text, if necessary.
            if (noText)
                hype.Text = text;

        // If the markup is empty, generate the markup for a placeholder.
        if(designTimeMarkup == null || designTimeMarkup.Length == 0)
            designTimeMarkup = GetEmptyDesignTimeHtml();

        return designTimeMarkup;
    } // GetDesignTimeHtml
} // CustomHyperLinkDesigner

The following code example shows how to derive the CustomHyperLink control from the HyperLink control and apply a DesignerAttribute attribute on the CustomHyperLink control to associate it with the CustomHyperLinkDesigner.

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

namespace Examples.CS.WebControls.Design
    // The CustomHyperLink is a copy of the HyperLink.
    // It uses the CustomHyperLinkDesigner for design-time support. 
        Level = AspNetHostingPermissionLevel.Minimal)]
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class CustomHyperLink : HyperLink
    } // CustomHyperLink
} // 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