HtmlTextWriter.GetAttributeKey(String) Método

Definición

Obtiene el valor de la enumeración HtmlTextWriterAttribute correspondiente para el atributo especificado.

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

Parámetros

attrName
String

Cadena con el atributo para el que se de ha obtener el valor de HtmlTextWriterAttribute.

Devoluciones

HtmlTextWriterAttribute

Valor de la enumeración HtmlTextWriterAttribute para el atributo especificado; en caso contrario, un valor HtmlTextWriterAttribute no válido si el atributo no es un miembro de la enumeración.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar una clase, derivada de la HtmlTextWriter clase , que invalida el RenderBeginTag método . La invalidación comprueba si tagKey es igual al Font campo , lo que indica que se representará un <font> elemento de marcado. Si es así, la invalidación llama al IsAttributeDefined método para averiguar si el <font> elemento contiene un Size atributo . IsAttributeDefined Si devuelve false, el AddAttribute método llama al GetAttributeKey método , que define y Size establece su valor en 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

Comentarios

Si attrName es null o una cadena vacía (""), o no se encuentra en la tabla de nombres de atributo, se devuelve el valor -1, escrito en un HtmlTextWriterAttribute objeto.

Se aplica a

Consulte también