Share via


XhtmlTextWriter.IsValidFormAttribute(String) 메서드

정의

<form> 요소의 여는 태그에 XHTML 특성을 렌더링할 수 있는지 확인합니다.

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.ExitStyle 메서드를 HtmlTextWriter.EnterStyle 사용하여 렌더링됩니다. 값이 이 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 문서 유형별로 지원 되는지 여부에 따라 특성을 렌더링 하는 데 유용 합니다.

적용 대상