HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Méthode

Définition

Obtient le nom d’attribut de style de balisage associé à la valeur d’énumération spécifiée HtmlTextWriterStyle .

protected:
 System::String ^ GetStyleName(System::Web::UI::HtmlTextWriterStyle styleKey);
protected string GetStyleName(System.Web.UI.HtmlTextWriterStyle styleKey);
member this.GetStyleName : System.Web.UI.HtmlTextWriterStyle -> string
Protected Function GetStyleName (styleKey As HtmlTextWriterStyle) As String

Paramètres

styleKey
HtmlTextWriterStyle

Pour HtmlTextWriterStyle obtenir le nom de l’attribut de style.

Retours

Nom de l’attribut de style associé à la valeur d’énumération HtmlTextWriterStyle spécifiée dans styleKey.

Exemples

L’exemple de code suivant montre comment vérifier si un <label> élément est rendu. Dans ce cas, il vérifie si un Color attribut de style a été défini sur l’élément. Si l’attribut n’a pas été défini, la AddStyleAttribute méthode est appelée et la GetStyleName méthode convertit le Color membre d’énumération en sa représentation sous forme de chaîne pour passer à la AddStyleAttribute méthode.

// If the markup element being rendered is a Label,
// render the opening tag of a <Font> element before it.
if ( tagKey == HtmlTextWriterTag::Label )
{
   
   // Check whether a Color style attribute is
   // included on the Label. If not, use the
   // AddStyleAttribute and GetStyleName methods to add one
   // and set its value to red.
   if (  !IsStyleAttributeDefined( HtmlTextWriterStyle::Color ) )
   {
      AddStyleAttribute( GetStyleName( HtmlTextWriterStyle::Color ), "red" );
   }
// If the markup element being rendered is a Label,
// render the opening tag of a Font element before it.
if (tagKey == HtmlTextWriterTag.Label)
{
    // Check whether a Color style attribute is 
    // included on the Label. If not, use the
    // AddStyleAttribute and GetStyleName methods to add one
    // and set its value to red.
    if (!IsStyleAttributeDefined(HtmlTextWriterStyle.Color))
    {
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red");
    }
' If the markup element being rendered is a Label,
' render the opening tag of a Font element before it.
If tagKey = HtmlTextWriterTag.Label Then
    ' Check whether a Color style attribute is 
    ' included on the Label. If not, use the
    ' AddStyleAttribute and GetStyleName methods to add one
    ' and set its value to red.
    If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then
        AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red")
    End If

Remarques

Si styleKey ce n’est pas un objet valide HtmlTextWriterStyle , la GetStyleName méthode retourne une chaîne vide («  »).

S’applique à

Voir aussi