ControlDesigner.GetEmptyDesignTimeHtml Metoda

Definice

Načte kód HTML představující ovládací prvek webového serveru v době návrhu, který nebude mít za běhu žádné vizuální znázornění.

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

Návraty

Kód HTML použitý k reprezentaci ovládacího prvku v době návrhu, který by jinak neměl žádnou vizuální reprezentaci. Výchozí hodnota je obdélník, který obsahuje typ a ID komponenty.

Příklady

Následující příklad kódu ukazuje, jak přepsat metodu GetDesignTimeHtml v návrháři vlastních ovládacích prvků. Text Pokud je vlastnost přidruženého ovládacího prvku prázdná, metoda volá GetEmptyDesignTimeHtml metodu GetDesignTimeHtml . V opačném GetDesignTimeHtml případě metoda vytvoří a vykreslí ovládací prvek Hyperlink .

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

Poznámky

Výchozí chování GetEmptyDesignTimeHtml metody je vrácení řetězce, který obsahuje název komponenty. Metoda GetEmptyDesignTimeHtml by měla být volána v implementaci GetDesignTimeHtml metody, pokud není k dispozici kód HTML v době návrhu.

Platí pro

Viz také