XhtmlTextWriter.IsValidFormAttribute(String) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Controleert een XHTML-kenmerk om ervoor te zorgen dat het kan worden weergegeven in de openingstag van een <form> element.
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
Parameters
- attributeName
- String
De kenmerknaam die moet worden gecontroleerd.
Retouren
trueals het kenmerk kan worden toegepast op een <form> element; anders. false
Voorbeelden
Het volgende codevoorbeeld maakt deel uit van een groter voorbeeld waarmee een aangepast Label besturingselement wordt gemaakt en een adapter waarmee de inhoud van het besturingselement wordt weergegeven als XHTML.
In dit codevoorbeeld ziet u hoe u een Booleaanse variabele met de naam attTest maakt en instelt op de retourwaarde die het resultaat is van het aanroepen van de IsValidFormAttribute methode met de parameterwaarde 'style'. Als de IsValidFormAttribute methode wordt geretourneerd true, worden de stijlen die aan het besturingselement zijn gekoppeld, weergegeven met behulp van de HtmlTextWriter.EnterStyle en HtmlTextWriter.ExitStyle methoden. Als de attTest waarde is false, worden de stijlen niet weergegeven. In plaats daarvan geeft de pagina de tekst weer voor het besturingselement, een <br/> element dat door de WriteBreak methode wordt weergegeven en een tekenreeks die de gebruiker informeert dat de XHTML-inhoud van het besturingselement voorwaardelijk is weergegeven.
Dit codevoorbeeld maakt deel uit van een groter voorbeeld voor de XhtmlTextWriter klasse.
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
Opmerkingen
Deze methode is handig om een kenmerk voorwaardelijk weer te geven, afhankelijk van of het wordt ondersteund door het XHTML-documenttype van het aanvragende apparaat.