Related Enumerations


HtmlTextWriter and Related Enumerations

In Table 8-1, you saw that each rendering method of the Control class takes a System.Web.UI.HtmlTextWriter object as a parameter. HtmlTextWriter derives from System.IO.TextWriter , which provides the capability of writing text to an output stream. HtmlTextWriter adds to the functionality of the base class by providing methods that simplify the writing and formatting of HTML tags and attributes. In the MetaTag control (Listing 8-1), we invoked some of the methods of HtmlTextWriter (such as AddAttribute , RenderBeginTag , and RenderEndTag ) to render HTML tags and attributes on the tags. Later in this chapter, we'll look at another example, LoginUI (Listing 8-5), which utilizes the AddStyleAttribute method of HtmlTextWriter to render CSS style attributes.

Various methods of HtmlTextWriter take as their arguments the values of the following three enumerations ” HtmlTextWriterTag , HtmlTextWriterAttribute , and HtmlTextWriterStyle . These enumerations list common HTML 4.0 tag names , attributes, and CSS style attributes. Many methods of HtmlTextWriter are overloaded; you can pass in either a string or an enumerated value as an argument. If you use the enumerations, you gain a number of benefits. Most important is the automatic downlevel rendering of HTML tags by using the HTML 3.2 subset, as we'll describe at the end of this chapter, in the section "Downlevel Rendering." When you use an enumerated value such as HtmlText ­WriterTag.Meta instead of using the string " meta" , you gain the benefit of type checking, which eliminates errors that could result from an incorrect string value. In addition, when you use the enumerations, you get IntelliSense support in Microsoft Visual Studio .NET, which displays the enumeration values in the code editor. Let's look at the enumerations next .

HtmlTextWriterTag Enumeration

The HtmlTextWriterTag enumeration contains values such as Button , Div , Input , and Span that map to standard HTML 4.0 tags with the same names. For example, HtmlTextWriterTag.Button maps to the <button> HTML tag. For a complete list of values, see the HtmlTextWriterTag enumeration in the System.Web.UI namespace. We use the HtmlTextWriterTag enumeration in the MetaTag (Listing 8-1) and the LoginUI (Listing 8-5) examples in this chapter.

HtmlTextWriterAttribute Enumeration

The HtmlTextWriterAttribute enumeration contains values such as Background , Border , Height , Href , and Id that map to standard HTML 4.0 attributes with the same names. For example, HtmlTextWriterAttribute.Background maps to the background attribute on the <body> tag. For a complete list of values, see the HtmlTextWriterAttribute enumeration in the System.Web.UI namespace. We use the HtmlTextWriterAttribute enumeration in this chapter's MetaTag (Listing 8-1) and LoginUI (Listing 8-5) examples.

HtmlTextWriterStyle Enumeration

The HtmlTextWriterStyle enumeration contains values such as BackgroundColor , BorderStyle , Color , FontFamily , and Width that map to standard HTML 4.0 CSS style attributes such as background-color , border-style , color , font-family , and width . For a complete list of values, see the HtmlTextWriterStyle enumeration in the System.Web.UI namespace. We use the HtmlTextWriterStyle enumeration in the LoginUI (Listing 8-5) example in this chapter.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net