ControlDesigner.GetEmptyDesignTimeHtml Méthode

Définition

Récupère le balisage HTML pour représenter un contrôle serveur web au moment du design qui n’aura aucune représentation visuelle au moment de l’exécution.

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

Retours

Balisage HTML utilisé pour représenter un contrôle au moment du design qui autrement n’aurait aucune représentation visuelle. La valeur par défaut est un rectangle qui contient le type et l’ID du composant.

Exemples

L’exemple de code suivant montre comment remplacer la GetDesignTimeHtml méthode dans un concepteur de contrôles personnalisé. Si la Text propriété du contrôle associé est vide, la GetDesignTimeHtml méthode appelle GetEmptyDesignTimeHtml la méthode . Sinon, la GetDesignTimeHtml méthode crée et restitue un Hyperlink contrôle.

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

Remarques

Le comportement par défaut de la GetEmptyDesignTimeHtml méthode consiste à retourner une chaîne qui contient le nom du composant. La GetEmptyDesignTimeHtml méthode doit être appelée dans l’implémentation de la GetDesignTimeHtml méthode lorsqu’il n’existe aucun balisage HTML au moment du design.

S’applique à

Voir aussi