HtmlTextWriter.GetStyleName(HtmlTextWriterStyle) Méthode

Définition

Obtient le nom de l'attribut de style de balisage associé à la valeur d'énumération HtmlTextWriterStyle spécifiée.Obtains the markup style attribute name associated with the specified HtmlTextWriterStyle enumeration value.

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

HtmlTextWriterStyle pour lequel obtenir le nom d'attribut de style.The HtmlTextWriterStyle to obtain the style attribute name for.

Retours

Nom de l'attribut de style associé à la valeur d'énumération HtmlTextWriterStyle spécifiée dans styleKey.The style attribute name associated with the HtmlTextWriterStyle enumeration value specified in styleKey.

Exemples

L’exemple de code suivant montre comment vérifier si un <label> élément est rendu.The following code example shows how to check whether a <label> element is being rendered. Si c’est le cas, il Color vérifie si un attribut de style a été défini sur l’élément.If so, it checks whether a Color style attribute has been defined on the element. Si l’attribut n’a pas été défini, AddStyleAttribute la méthode est appelée et GetStyleName la méthode convertit le membre de l' Color énumération en sa représentation AddStyleAttribute sous forme de chaîne à passer à la méthode.If the attribute has not been defined, the AddStyleAttribute method is called and the GetStyleName method converts the Color enumeration member into its string representation to pass to the AddStyleAttribute method.

// 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 n’est pas un HtmlTextWriterStyle objet valide, GetStyleName la méthode retourne une chaîne vide ("").If styleKey is not a valid HtmlTextWriterStyle object, the GetStyleName method returns an empty string ("").

S’applique à

Voir aussi