Prev | Current Page 124 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

WriteEndTag("h3");
Rendering the Table
Once the control header content is rendered, we move on to building the HTML table in the
RenderTable() method. This portion of the control demonstrates a nifty feature of the
HtmlTextWriter in working with HTML attributes. The AddAttribute() method takes a key/value
string pair for each attribute you wish to render on an HTML tag. You can call this method
multiple times to build up as many attributes to the follow-on tag as necessary. Once you??™ve
finished adding attributes, the next step is to use the RenderBeginTag() method. This method is
smart enough to look at the attributes that were added previously and render them into the
final output stream along with the tag name and brackets. The RenderTable() method uses this
functionality to build the tag and add a Border attribute to it:
// write

writer.AddAttribute(HtmlTextWriterAttribute.Border,"1");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
EqualsDoubleQuoteString =""
SelfClosingChars /
SelfClosingTagEnd />
SemicolonChar ;
SingleQuoteChar '
SlashChar /
SpaceChar Space
StyleEqualsChar :
TagLeftChar <
TagRightChar >
Table 2-1. String Fields Exposed by HtmlTextWriter (Continued)
HtmlTextWriter Field String Output
CHAPTER 2 ?–  ENCAPSULATING FUNCT IONALITY IN ASP.


Pages:
112113114115116117118119120121122123 124 125126127128129130131132133134135136