HyperLinkDesigner Class
Assembly: System.Design (in system.design.dll)
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
- SecurityPermission for calling unmanaged code. Demand value: Demand. Permission value: UnmanagedCode
System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.TextControlDesigner
System.Web.UI.Design.WebControls.HyperLinkDesigner