Prev | Current Page 217 | Next

Rob Cameron and Dale Michalk

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


136 CHAPTER 4 ?–  T HE WEBCONTROL BASE CLASS AND CONTROL S TYLES
For those who need to render attributes on the outer tag, the AddAttributesToRender()
method is a method override available when inheriting from WebControl that fits the bill. It is
part of the customized Render() process that WebControl orchestrates, and it is called by the
RenderBeginTag() method of WebControl. The WebControl version of Render() executes the
following routines in order, with RenderBeginTag() calling AddAttributesToRender():
??? RenderBeginTag()
??? RenderContents()
??? RenderEndTag()
Figure 4-7 shows the relationship graphically.
Figure 4-7. The rendering process in the WebControl class
Depending on the level of control required, you can overload each step of the process as
necessary. The RenderBeginTag()/RenderEndTag() method pairs are less commonly overloaded,
because they do the outer tag rendering by looking up the TagKey or TagName property values
and emitting the content via HtmlTextWriter.
The key point to remember is that when you override AddAttributesToRender(), you must
also call the base WebControl version of the method to ensure that the style properties managed
by WebControl are emitted properly:
base.AddAttributesToRender(writer);
Also, you can use HtmlTextWriter and its AddAttribute() method to add other attributes as
necessary:
writer.


Pages:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229