Prev | Current Page 130 | Next

Rob Cameron and Dale Michalk

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

For those who were worried
about the HtmlTextWriter class and its efficiencies, the Render() and Write() methods write to a
buffer, so there aren??™t any performance concerns about calling these methods multiple times.
Once we have built up the string content, we next use the InnerHtml property to easily load
the HTML information inside the

control. The final step is to add the HtmlGenericControl
to the Controls collection of our new custom server control.
Building the HTML table in the BuildTable() method follows the well worn process of
programmatically building up the HtmlTable control??™s child content. The result is almost an
exact image of the user control version of the table. This is a good indication of the strength of
custom controls when it comes to dynamic generation. The declarative advantages of the user
control are not as powerful when content is built on the fly.
Using the Custom Table Controls
To verify that both custom controls provide identical HTML output, we use a web form that
hosts them side by side in an HTML table. Figure 2-9 shows that they have the same Designer
capability, though TableCompCustomControl requires the additional Designer attribute on its
class to render correctly at design time, as discussed previously.


Pages:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142