Export (0) Print
Expand All

ButtonDesigner.GetDesignTimeHtml Method

Gets the markup that is used to render the associated control at design time.

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

public override string GetDesignTimeHtml()

Return Value

Type: System.String
A String containing the markup used to render the Button at design time.

The GetDesignTimeHtml method replaces the Text property with the ID property of the Button control if the Text contains no displayable characters. Then, the GetDesignTimeHtml method calls its base method, ControlDesigner.GetDesignTimeHtml, which calls into the Control.RenderControl method to generate the markup.

Notes to Inheritors

If you are overriding the GetDesignTimeHtml method, typically you will modify selected property values, then call the base method to generate the markup, and then restore the properties to their original values.

The following code example demonstrates how to override the GetDesignTimeHtml method to change the generated markup.

If the BorderStyle property has not been set previously (that is, it has the NotSet field value), a call to the GetDesignTimeHtml method sets it to a blue-dashed border with a width of three pixels, and then displays that border on the design surface. If the BorderStyle property has been set, the existing border property values are displayed.

Typically, the GetDesignTimeHtml calls its base method, ControlDesigner.GetDesignTimeHtml, which calls into the Control.RenderControl method of the associated control to generate the markup.

' Create a class that derives from ButtonDesigner 
' and displays the custom SampleButton control 
' on the design surface. 
Imports System
Imports System.Web.UI.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls

Namespace Examples.AspNet 


    Public Class SampleButtonDesigner
        Inherits ButtonDesigner

        ' Override the GetDesignTimeHtml method. 
        Public Overrides Function GetDesignTimeHtml() As String 

            Dim sampleButton As SampleButton = CType(Component, SampleButton)
            Dim designTimeHtml As String = Nothing 

            ' Check the control's BorderStyle property 
            ' to conditionally render design-time HTML. 
            If (sampleButton.BorderStyle = BorderStyle.NotSet) Then 

                ' Create variables to hold current property settings. 
                Dim oldBorderStyle As BorderStyle = sampleButton.BorderStyle
                Dim oldBorderWidth As Unit = sampleButton.BorderWidth
                Dim oldBorderColor As Color = sampleButton.BorderColor

                ' Set properties and the design-time HTML. 
                Try
                    sampleButton.BorderStyle = BorderStyle.Dashed
                    sampleButton.BorderWidth = Unit.Pixel(3)
                    sampleButton.BorderColor = Color.Blue
                    designTimeHtml = MyBase.GetDesignTimeHtml()

                    ' If an exception occurs, call the GetErrorDesignTimeHtml 
                    ' method. 
                Catch ex As Exception
                    designTimeHtml = GetErrorDesignTimeHtml(ex)

                    ' Return properties to their original settings. 
                Finally
                    sampleButton.BorderStyle = oldBorderStyle
                    sampleButton.BorderWidth = oldBorderWidth
                    sampleButton.BorderColor = oldBorderColor
                End Try 

            Else
                designTimeHtml = MyBase.GetDesignTimeHtml()
            End If 

            Return designTimeHtml

        End Function 

    End Class 
End Namespace

.NET Framework

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

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft