ButtonDesigner.GetDesignTimeHtml 方法

定义

获取用于在设计时呈现关联控件的标记。

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String

返回

一个 String,其中包含用于在设计时呈现 Button 的标记。

示例

下面的代码示例演示如何重写 GetDesignTimeHtml 方法以更改生成的标记。

BorderStyle如果属性之前尚未设置 (,则具有NotSet字段值) ,对 方法的GetDesignTimeHtml调用将其设置为宽度为 3 像素的蓝色虚线边框,然后在设计图面上显示该边框。 BorderStyle如果已设置属性,则显示现有边框属性值。

通常, GetDesignTimeHtml 调用其基方法 , ControlDesigner.GetDesignTimeHtml后者调用 Control.RenderControl 关联控件的 方法以生成标记。

' Create a class that derives from ButtonDesigner
' and displays the custom SampleButton control
' on the design surface.
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

注解

如果 Text 不包含任何可显示的字符,TextGetDesignTimeHtml 方法会将 属性ID替换为 控件的 Button 属性。 然后, GetDesignTimeHtml 该方法调用其基方法 , ControlDesigner.GetDesignTimeHtml该基方法调用 Control.RenderControl 方法以生成标记。

继承者说明

如果要重写 GetDesignTimeHtml() 方法,通常会修改所选属性值,然后调用基方法以生成标记,然后将属性还原为其原始值。

适用于

另请参阅