HtmlTextWriter.GetAttributeKey(String) Méthode

Définition

Obtient la valeur d’énumération correspondante HtmlTextWriterAttribute pour l’attribut spécifié.

protected:
 System::Web::UI::HtmlTextWriterAttribute GetAttributeKey(System::String ^ attrName);
protected System.Web.UI.HtmlTextWriterAttribute GetAttributeKey(string attrName);
member this.GetAttributeKey : string -> System.Web.UI.HtmlTextWriterAttribute
Protected Function GetAttributeKey (attrName As String) As HtmlTextWriterAttribute

Paramètres

attrName
String

Chaîne qui contient l’attribut pour lequel obtenir le HtmlTextWriterAttribute.

Retours

Valeur HtmlTextWriterAttribute d’énumération de l’attribut spécifié ; sinon, valeur non valide HtmlTextWriterAttribute si l’attribut n’est pas membre de l’énumération.

Exemples

L’exemple de code suivant montre comment utiliser une classe dérivée de la HtmlTextWriter classe, qui remplace la RenderBeginTag méthode. La substitution vérifie si tagKey elle est égale au Font champ, ce qui indique qu’un <font> élément de balisage sera rendu. Dans ce cas, le remplacement appelle la IsAttributeDefined méthode pour déterminer si l’élément <font> contient un Size attribut. Si le IsAttributeDefined retour est retourné false, la AddAttribute méthode appelle la GetAttributeKey méthode, qui définit la Size valeur et définit sa valeur 30pt.

// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point.
if ( tagKey == HtmlTextWriterTag::Font )
{
   if (  !IsAttributeDefined( HtmlTextWriterAttribute::Size ) )
   {
      AddAttribute( GetAttributeKey( "size" ), "30pt" );
   }
}
// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point. 
if (tagKey == HtmlTextWriterTag.Font)
{
    if (!IsAttributeDefined(HtmlTextWriterAttribute.Size))
    {
        AddAttribute(GetAttributeKey("size"), "30pt");
    }
}
' If the tagKey parameter is set to a <font> element
' but a size attribute is not defined on the element,
' the AddStyleAttribute method adds a size attribute
' and sets it to 30 point. 
If tagKey = HtmlTextWriterTag.Font Then
    If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then
        AddAttribute(GetAttributeKey("size"), "30pt")
    End If
End If

Remarques

S’il attrName s’agit null d’une chaîne vide («  »), ou introuvable dans la table des noms d’attributs, la valeur -1, typée dans un HtmlTextWriterAttribute objet, est retournée.

S’applique à

Voir aussi