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 된 부울 변수를 만들고 매개 변수 값 "style"을 사용하여 메서드를 호출 IsValidFormAttribute 한 결과로 반환 값으로 설정하는 방법을 보여 줍니다. 메서드가 IsValidFormAttribute 반환true되면 컨트롤과 연결된 스타일은 및 HtmlTextWriter.EnterStyle 메서드를 HtmlTextWriter.ExitStyle 사용하여 렌더링됩니다. 값이 attTestfalse면 스타일이 렌더링되지 않습니다. 대신 페이지에 컨트롤의 텍스트, <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 문서 형식에서 지원하는지 여부에 따라 특성을 조건부로 렌더링하는 데 유용합니다.

적용 대상