XhtmlTextWriter.IsValidFormAttribute(String) Метод

Определение

Проверяет атрибут XHTML, чтобы убедиться, что он может быть отображен в открываемом теге <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

Параметры

attributeName
String

Имя атрибута для проверки.

Возвращаемое значение

trueЗначение , <form>если атрибут может быть применен к элементуfalse; в противном случае .

Примеры

Следующий пример кода является частью более крупного примера, который создает пользовательский Label элемент управления и адаптер, который отображает содержимое элемента управления как XHTML.

В этом примере кода показано, как создать логическую переменную с именем attTest и задать возвращаемое значение, которое приводит к вызову IsValidFormAttribute метода со значением параметра "style". IsValidFormAttribute Если метод возвращаетсяtrue, стили, связанные с элементом управления, отображаются с помощью HtmlTextWriter.EnterStyle методов и HtmlTextWriter.ExitStyle методов. attTest Если значение равноfalse, стили не отображаются. Вместо этого на странице отображается текст элемента управления, <br/> элемент, отрисованный методом WriteBreak , и текстовая строка, информирующая пользователя о том, что содержимое XHTML элемента управления отрисовывается условно.

Этот пример кода является частью более крупного примера, предоставленного для 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

Комментарии

Этот метод полезен для условной отрисовки атрибута в зависимости от того, поддерживается ли он типом документа XHTML запрашивающего устройства.

Применяется к