XhtmlTextWriter.IsValidFormAttribute(String) Método

Definición

Comprueba un atributo XHTML para garantizar que se puede representar en la etiqueta de apertura de un elemento <form>.

public:
 override bool IsValidFormAttribute(System::String ^ attributeName);
public override bool IsValidFormAttribute (string attributeName);
override this.IsValidFormAttribute : string -> bool
Public Overrides Function IsValidFormAttribute (attributeName As String) As Boolean

Parámetros

attributeName
String

Nombre del atributo que se va a comprobar.

Devoluciones

Es true si el atributo se puede aplicar a un elemento <form>; en caso contrario, es false.

Ejemplos

El ejemplo de código siguiente forma parte de un ejemplo más grande que crea un control personalizado Label y un adaptador que representa el contenido del control como XHTML.

En este ejemplo de código se muestra cómo crear una variable booleana denominada attTest y establecerla en el valor devuelto que resulta de llamar al IsValidFormAttribute método con el valor de parámetro "style". Si el IsValidFormAttribute método devuelve true, los estilos asociados al control se representan mediante los HtmlTextWriter.EnterStyle métodos y HtmlTextWriter.ExitStyle . Si el attTest valor es false, los estilos no se representan. En su lugar, la página muestra el texto del control, un <br/> elemento representado por el WriteBreak método y una cadena de texto que informa al usuario de que el contenido XHTML del control se ha representado condicionalmente.

Este ejemplo de código es parte de un ejemplo mayor proporcionado para la clase XhtmlTextWriter.

protected override void Render(HtmlTextWriter writer)
{
    // Create an instance of the XhtmlTextWriter class,
    // named w, and cast the HtmlTextWriter passed 
    // in the writer parameter to w.
    XhtmlTextWriter w = new XhtmlTextWriter(writer);

    // Create a string variable, named value, to hold
    // the control's Text property value.
    String value = Control.Text;

    // Create a Boolean variable, named attTest,
    // to test whether the Style attribute is 
    // valid in the page that the control is
    // rendered to.
    Boolean attTest = w.IsValidFormAttribute("style");

    // Check whether attTest is true or false.
    // If true, a style is applied to the XHTML
    // content. If false, no style is applied.
    if (attTest)
        w.EnterStyle(Control.ControlStyle);

    // Write the Text property value of the control,
    // a <br> element, and a string. Consider encoding the value using WriteEncodedText.
    w.Write(value);
    w.WriteBreak();
    w.Write("This control conditionally rendered its styles for XHTML.");

    // Check whether attTest is true or false.
    // If true, the XHTML style is closed.
    // If false, nothing is rendered.
    if (attTest)
        w.ExitStyle(Control.ControlStyle);
}
' Override the Render method.
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

    ' Create an instance of the XhtmlTextWriter class, 
    ' named w, and cast the HtmlTextWriter passed 
    ' in the writer parameter to w.
    Dim w As XhtmlTextWriter = New XhtmlTextWriter(writer)

    ' Create a string variable, named value, to hold
    ' the control's Text property value.
    Dim value As String = Control.Text

    ' Create a Boolean variable, named attTest,
    ' to test whether the Style attribute is 
    ' valid in the page that the control is
    ' rendered to.
    Dim attTest As Boolean = w.IsValidFormAttribute("style")

    ' Check whether attTest is true or false.
    ' If true, a style is applied to the XHTML
    ' content. If false, no style is applied.
    If (attTest = True) Then
        w.EnterStyle(Control.ControlStyle)
    End If

    ' Write the Text property value of the control,
    ' a <br> element, and a string. Consider encoding the value using WriteEncodedText.
    w.Write(value)
    w.WriteBreak()
    w.Write("This control conditionally rendered its styles for XHTML.")

    ' Check whether attTest is true or false.
    ' If true, the XHTML style is closed.
    ' If false, nothing is rendered.
    If (attTest = True) Then
        w.ExitStyle(Control.ControlStyle)
    End If

End Sub

Comentarios

Este método es útil para representar condicionalmente un atributo en función de si es compatible con el tipo de documento XHTML del dispositivo solicitante.

Se aplica a