Export (0) Print
Expand All

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)

[SupportsPreviewControlAttribute(true)]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class HyperLinkDesigner : TextControlDesigner

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);

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