Bagikan melalui


ButtonDesigner.GetDesignTimeHtml Metode

Definisi

Mendapatkan markup yang digunakan untuk merender kontrol terkait pada waktu desain.

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

Mengembalikan

yang String berisi markup yang digunakan untuk merender pada Button waktu desain.

Contoh

Contoh kode berikut menunjukkan cara mengambil alih GetDesignTimeHtml metode untuk mengubah markup yang dihasilkan.

BorderStyle Jika properti belum diatur sebelumnya (yaitu, properti memiliki NotSet nilai bidang), panggilan ke GetDesignTimeHtml metode mengaturnya ke batas putus-putus biru dengan lebar tiga piksel, lalu menampilkan batas tersebut pada permukaan desain. BorderStyle Jika properti telah diatur, nilai properti batas yang ada akan ditampilkan.

Biasanya, GetDesignTimeHtml memanggil metode dasarnya, ControlDesigner.GetDesignTimeHtml, yang memanggil ke Control.RenderControl metode kontrol terkait untuk menghasilkan markup.

' 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

Keterangan

Metode GetDesignTimeHtml mengganti properti Text dengan ID properti Button kontrol jika tidak berisi karakter yang Text dapat ditampilkan. Kemudian, metode memanggil GetDesignTimeHtml metode dasarnya, ControlDesigner.GetDesignTimeHtml, yang memanggil ke metode Control.RenderControl untuk menghasilkan markup.

Catatan Bagi Inheritor

Jika Anda mengambil alih GetDesignTimeHtml() metode , biasanya Anda akan memodifikasi nilai properti yang dipilih, lalu memanggil metode dasar untuk menghasilkan markup, lalu memulihkan properti ke nilai aslinya.

Berlaku untuk

Lihat juga