HtmlTextWriter.GetAttributeKey(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o valor de enumeração correspondente HtmlTextWriterAttribute para o 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
Uma cadeia que contém o atributo para o qual obter o HtmlTextWriterAttribute.
Devoluções
O HtmlTextWriterAttribute valor de enumeração para o atributo especificado; caso contrário, um valor inválido HtmlTextWriterAttribute se o atributo não for membro da enumeração.
Exemplos
O exemplo de código seguinte demonstra como usar uma classe, derivada da HtmlTextWriter classe, que sobrepõe o RenderBeginTag método. O override verifica se tagKey é igual ao Font campo, o que indica que um <font> elemento de marcação será renderizado. Se sim, a sobreposição chama o IsAttributeDefined método para descobrir se o <font> elemento contém um Size atributo. Se o IsAttributeDefined devolver false, o AddAttribute método chama o GetAttributeKey método, que define o Size e define o seu valor para 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
Observações
Se attrName for null ou uma cadeia vazia (""), ou não puder ser encontrada na tabela dos nomes dos atributos, o valor -1, tipado num HtmlTextWriterAttribute objeto, é devolvido.