XhtmlTextWriter.IsValidFormAttribute(String) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Memeriksa atribut XHTML untuk memastikan bahwa atribut dapat dirender dalam tag <form> pembuka elemen.
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
Parameter
- attributeName
- String
Nama atribut untuk diperiksa.
Mengembalikan
true jika atribut dapat diterapkan ke <form> elemen; jika tidak, false.
Contoh
Contoh kode berikut adalah bagian dari contoh yang lebih besar yang membuat kontrol kustom Label dan adaptor yang merender konten kontrol sebagai XHTML.
Contoh kode ini menunjukkan cara membuat variabel Boolean bernama attTest dan mengaturnya ke nilai pengembalian yang dihasilkan dari memanggil IsValidFormAttribute metode dengan nilai parameter "style".
IsValidFormAttribute Jika metode mengembalikan true, gaya yang terkait dengan kontrol dirender menggunakan HtmlTextWriter.EnterStyle metode dan HtmlTextWriter.ExitStyle . Jika nilainya attTest adalah false, gaya tidak dirender. Sebagai gantinya, halaman menampilkan teks untuk kontrol, <br/> elemen yang dirender oleh WriteBreak metode , dan string teks yang memberi tahu pengguna bahwa konten XHTML kontrol telah dirender secara kondisional.
Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk XhtmlTextWriter kelas .
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
Keterangan
Metode ini berguna untuk merender atribut secara kondisional tergantung pada apakah itu didukung oleh jenis dokumen XHTML dari perangkat yang meminta.