Share via


ButtonDesigner.GetDesignTimeHtml Metodo

Definizione

Ottiene il markup usato per il rendering del controllo associato in fase di progettazione.

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

Restituisce

String

Oggetto String contenente il markup usato per eseguire il rendering dell'oggetto Button in fase di progettazione.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del GetDesignTimeHtml metodo per modificare il markup generato.

Se la BorderStyle proprietà non è stata impostata in precedenza (ovvero il valore del NotSet campo), una chiamata al GetDesignTimeHtml metodo lo imposta su un bordo tratteggiato blu con una larghezza di tre pixel e quindi visualizza tale bordo sull'area di progettazione. Se la BorderStyle proprietà è stata impostata, vengono visualizzati i valori delle proprietà del bordo esistenti.

In genere, chiama il GetDesignTimeHtml metodo di base , ControlDesigner.GetDesignTimeHtml, che chiama nel Control.RenderControl metodo del controllo associato per generare il 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

Commenti

Il GetDesignTimeHtml metodo sostituisce la Text proprietà con la ID proprietà del Button controllo se l'oggetto Text non contiene caratteri visualizzabili. Il metodo chiama quindi il GetDesignTimeHtml metodo di base , ControlDesigner.GetDesignTimeHtml, che chiama nel Control.RenderControl metodo per generare il markup.

Note per gli eredi

Se si esegue l'override del GetDesignTimeHtml() metodo , in genere si modificheranno i valori delle proprietà selezionate, chiamare il metodo di base per generare il markup e quindi ripristinare le proprietà sui valori originali.

Si applica a

Vedi anche