XhtmlTextWriter.IsValidFormAttribute(String) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Controlla un attributo XHTML per assicurarsi che possa essere eseguito il rendering nel tag di apertura di un <form> elemento.
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
Parametri
- attributeName
- String
Nome dell'attributo da controllare.
Valori restituiti
true se l'attributo può essere applicato a un <form> elemento; in caso contrario, false.
Esempio
L'esempio di codice seguente fa parte di un esempio più ampio che crea un controllo personalizzato Label e un adattatore che esegue il rendering del contenuto del controllo come XHTML.
Questo esempio di codice illustra come creare una variabile booleana denominata attTest e impostarla sul valore restituito risultante dalla chiamata al IsValidFormAttribute metodo con il valore del parametro "style". Se il IsValidFormAttribute metodo restituisce true, gli stili associati al controllo vengono sottoposti a rendering utilizzando i HtmlTextWriter.EnterStyle metodi e HtmlTextWriter.ExitStyle . Se il attTest valore è false, gli stili non vengono visualizzati. La pagina visualizza invece il testo per il controllo, un <br/> elemento di cui viene eseguito il WriteBreak rendering dal metodo e una stringa di testo che informa l'utente che il contenuto XHTML del controllo ha eseguito il rendering in modo condizionale.
Questo esempio di codice fa parte di un esempio più ampio fornito per la XhtmlTextWriter classe .
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
Commenti
Questo metodo è utile per eseguire il rendering condizionale di un attributo a seconda che sia supportato dal tipo di documento XHTML del dispositivo richiedente.