ControlDesigner.GetEmptyDesignTimeHtml Metod

Definition

Hämtar HTML-markering för att representera en webbserverkontroll vid designtillfället som inte har någon visuell representation vid körning.

protected:
 virtual System::String ^ GetEmptyDesignTimeHtml();
protected virtual string GetEmptyDesignTimeHtml();
abstract member GetEmptyDesignTimeHtml : unit -> string
override this.GetEmptyDesignTimeHtml : unit -> string
Protected Overridable Function GetEmptyDesignTimeHtml () As String

Returer

HTML-koden som används för att representera en kontroll vid designtillfället som annars inte skulle ha någon visuell representation. Standardvärdet är en rektangel som innehåller komponentens typ och ID.

Exempel

I följande kodexempel visas hur du åsidosätter GetDesignTimeHtml metoden i en anpassad kontrolldesigner. Om egenskapen Text för den associerade kontrollen är tom GetDesignTimeHtml anropar GetEmptyDesignTimeHtml metoden metoden. Annars GetDesignTimeHtml skapar och renderar metoden en Hyperlink kontroll.

public override string GetDesignTimeHtml()
{
    if (simpleControl.Text.Length > 0)
    {
        string spec = "<a href='{0}.aspx'>{0}</a>";
        return String.Format(spec, simpleControl.Text);
    }
    else
    {
        return GetEmptyDesignTimeHtml();
    }
}
Public Overrides Function GetDesignTimeHtml() As String
   ' Component is the instance of the component or control that
   ' this designer object is associated with. This property is 
   ' inherited from System.ComponentModel.ComponentDesigner.
   simpleControl = CType(Component, Simple)
   
   If simpleControl.Text.Length > 0 Then
      Dim sw As New StringWriter()
      Dim tw As New HtmlTextWriter(sw)
      
      Dim placeholderLink As New HyperLink()
      
      ' Put simpleControl.Text into the link's Text.
      placeholderLink.Text = simpleControl.Text
      placeholderLink.NavigateUrl = simpleControl.Text
      placeholderLink.RenderControl(tw)
      
      Return sw.ToString()
   Else
      Return GetEmptyDesignTimeHtml()
   End If
End Function

Kommentarer

Standardbeteendet för GetEmptyDesignTimeHtml metoden är att returnera en sträng som innehåller komponentens namn. Metoden GetEmptyDesignTimeHtml ska anropas i implementeringen av GetDesignTimeHtml metoden när det inte finns någon HTML-kod för designtid.

Gäller för

Se även