XhtmlTextWriter.IsValidFormAttribute Method (String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Checks an XHTML attribute to ensure that it can be rendered in the opening tag of a <form> element.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public override bool IsValidFormAttribute(
	string attributeName
)

Parameters

attributeName
Type: System.String

The attribute name to check.

Return Value

Type: System.Boolean

true if the attribute can be applied to a <form> element; otherwise, false.

This method is useful to conditionally render an attribute depending on whether it is supported by the XHTML document type of the requesting device.

The following code example is part of a larger example that creates a custom Label control and an adapter that renders the content of the control as XHTML.

This code example demonstrates how to create a Boolean variable named attTest and set it to the return value that results from calling the IsValidFormAttribute method with the parameter value "style". If the IsValidFormAttribute method returns true, the styles that are associated with the control are rendered using the HtmlTextWriter.EnterStyle and HtmlTextWriter.ExitStyle methods. If the attTest value is false, the styles are not rendered. Instead, the page displays the text for the control, a <br/> element that is rendered by the WriteBreak method, and a text string informing the user that the XHTML content of the control has rendered conditionally.

This code example is part of a larger example provided for the XhtmlTextWriter class.

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);
}

.NET Framework
Available since 2.0
Return to top
Show: