XhtmlTextWriter.IsValidFormAttribute(String) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Kontrollerar ett XHTML-attribut för att säkerställa att det kan återges i öppningstaggen för ett <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
Parametrar
- attributeName
- String
Det attributnamn som ska kontrolleras.
Returer
trueom attributet kan tillämpas på ett <form> element, annars . false
Exempel
Följande kodexempel är en del av ett större exempel som skapar en anpassad Label kontroll och ett kort som återger innehållet i kontrollen som XHTML.
Det här kodexemplet visar hur du skapar en boolesk variabel med namnet attTest och anger det till det returvärde som är resultatet av att anropa IsValidFormAttribute metoden med parametervärdet "style".
IsValidFormAttribute Om metoden returnerar truerenderas de formatmallar som är associerade med kontrollen med metoderna HtmlTextWriter.EnterStyle och HtmlTextWriter.ExitStyle . Om värdet attTest är falseåterges inte formatmallarna. I stället visar sidan texten för kontrollen, ett <br/> element som återges av WriteBreak metoden och en textsträng som informerar användaren om att XHTML-innehållet i kontrollen har renderats villkorligt.
Det här kodexemplet är en del av ett större exempel för XhtmlTextWriter klassen.
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
Kommentarer
Den här metoden är användbar för att villkorligt återge ett attribut beroende på om det stöds av XHTML-dokumenttypen för den begärande enheten.