共用方式為


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會將它設定為寬度為三圖元的藍色虛線框線,然後在設計介面上顯示該框線。 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 不包含任何可顯示字元,Button方法GetDesignTimeHtml會將 Text 屬性ID取代為 控件的屬性。 然後,方法會 GetDesignTimeHtml 呼叫其基底方法 , ControlDesigner.GetDesignTimeHtml它會呼叫 Control.RenderControl 方法以產生標記。

給繼承者的注意事項

如果您要覆寫 GetDesignTimeHtml() 方法,通常會修改選取的屬性值,然後呼叫基底方法來產生標記,然後將屬性還原至其原始值。

適用於

另請參閱