HtmlTextWriter.GetAttributeKey(String) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene il valore di enumerazione corrispondente HtmlTextWriterAttribute per l'attributo specificato.
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
Parametri
- attrName
- String
Stringa contenente l'attributo per il quale ottenere l'oggetto HtmlTextWriterAttribute.
Valori restituiti
Valore HtmlTextWriterAttribute di enumerazione per l'attributo specificato; in caso contrario, un valore non valido HtmlTextWriterAttribute se l'attributo non è un membro dell'enumerazione.
Esempio
Nell'esempio di codice seguente viene illustrato come usare una classe, derivata dalla HtmlTextWriter classe , che esegue l'override del RenderBeginTag metodo . L'override controlla se tagKey è uguale al campo, che indica che verrà eseguito il Font rendering di un <font> elemento di markup. In tal caso, l'override chiama il IsAttributeDefined metodo per determinare se l'elemento <font> contiene un Size attributo.
IsAttributeDefined Se restituisce false, il AddAttribute metodo chiama il GetAttributeKey metodo , che definisce l'oggetto Size e imposta il relativo valore su 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
Commenti
Se attrName è null o una stringa vuota ("") o non è possibile trovare nella tabella dei nomi degli attributi, viene restituito il valore -1, digitato in un HtmlTextWriterAttribute oggetto .