HtmlTextWriter.OnStyleAttributeRender 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.
Determina se o atributo de estilo de marcação especificado e o seu valor podem ser representados no elemento de marcação atual.
protected:
virtual bool OnStyleAttributeRender(System::String ^ name, System::String ^ value, System::Web::UI::HtmlTextWriterStyle key);
protected virtual bool OnStyleAttributeRender(string name, string value, System.Web.UI.HtmlTextWriterStyle key);
abstract member OnStyleAttributeRender : string * string * System.Web.UI.HtmlTextWriterStyle -> bool
override this.OnStyleAttributeRender : string * string * System.Web.UI.HtmlTextWriterStyle -> bool
Protected Overridable Function OnStyleAttributeRender (name As String, value As String, key As HtmlTextWriterStyle) As Boolean
Parâmetros
- name
- String
Uma string contendo o nome do atributo style a renderizar.
- value
- String
Uma cadeia contendo o valor atribuído ao atributo style.
O HtmlTextWriterStyle atributo associado ao estilo.
Devoluções
Sempre true.
Exemplos
O seguinte exemplo de código mostra como sobrescrever o OnStyleAttributeRender método. Se um Color atributo style for renderizado, mas o Color valor não purplefor , o OnStyleAttributeRender override usa o AddStyleAttribute método para definir o Color atributo como purple.
// If a color style attribute is to be rendered,
// compare its value to purple. If it is not set to
// purple, add the style attribute and set the value
// to purple, then return false.
protected override bool OnStyleAttributeRender(string name,
string value,
HtmlTextWriterStyle key)
{
if (key == HtmlTextWriterStyle.Color)
{
if (string.Compare(value, "purple") != 0)
{
AddStyleAttribute("color", "purple");
return false;
}
}
// If the style attribute is not a color attribute,
// use the base functionality of the
// OnStyleAttributeRender method.
return base.OnStyleAttributeRender(name, value, key);
}
' If a color style attribute is to be rendered,
' compare its value to purple. If it is not set to
' purple, add the style attribute and set the value
' to purple, then return false.
Protected Overrides Function OnStyleAttributeRender(name As String, _
value As String, _
key As HtmlTextWriterStyle) _
As Boolean
If key = HtmlTextWriterStyle.Color Then
If [String].Compare(value, "purple") <> 0 Then
AddStyleAttribute("color", "purple")
Return False
End If
End If
' If the style attribute is not a color attribute,
' use the base functionality of the
' OnStyleAttributeRender method.
Return MyBase.OnStyleAttributeRender(name, value, key)
End Function 'OnStyleAttributeRender
Observações
A HtmlTextWriter implementação de classes do OnStyleAttributeRender método devolve truesempre . Os OnStyleAttributeRender overrides podem determinar se um atributo style será renderizado na página.
Notas para Herdeiros
Se herdar da HtmlTextWriter classe, pode sobrescrever o OnStyleAttributeRender(String, String, HtmlTextWriterStyle) método para regressar false e impedir que um atributo style seja renderizado, seja renderizado num determinado elemento ou seja renderizado para uma linguagem de marcação específica. Por exemplo, se não quiseres que o objeto derivado de renderize o HtmlTextWriter atributo style para um color elemento, podes sobrescrever o <p> and return OnStyleAttributeRender(String, String, HtmlTextWriterStyle) quando false passa name e o color valor da propriedade é TagName.p