Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)

'Declaration
Public Class HyperLinkDesigner
	Inherits TextControlDesigner
'Usage
Dim instance As HyperLinkDesigner

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
    Inherits HyperLinkDesigner

    ' Override the GetDesignTimeHtml to set the CustomHyperLink Text
    ' property so that it displays at design time.
    Public Overrides Function GetDesignTimeHtml() As String

        Dim hype As CustomHyperLink = CType(Component, CustomHyperLink)
        Dim designTimeMarkup As String = Nothing

        ' Save the original Text and note if it is empty.
        Dim text As String = hype.Text
        Dim noText As Boolean = (text.Trim().Length = 0)

        Try
            ' If the Text is empty, supply a default value.
            If noText Then
                hype.Text = "Click here."
            End If

            ' Call the base method to generate the markup.
            designTimeMarkup = MyBase.GetDesignTimeHtml()

        Catch ex As Exception
            ' 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 Then
                hype.Text = text
            End If
        End Try

        ' If the markup is empty, generate the markup for a placeholder.
        If ((designTimeMarkup = Nothing) Or _
            (designTimeMarkup.Length = 0)) Then
            designTimeMarkup = GetEmptyDesignTimeHtml()
        End If

        Return designTimeMarkup

    End Function ' GetDesignTimeHtml
End Class ' 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.

Imports System.Web
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Examples.VB.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(GetType(Examples.VB.WebControls.Design. _
        CustomHyperLinkDesigner))> _
    Public Class CustomHyperLink
        Inherits HyperLink
    End Class ' CustomHyperLink
End Namespace ' Examples.VB.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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.