Prev | Current Page 426 | Next

Rob Cameron and Dale Michalk

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

aspx page. Sometimes, web developers must generate the templates on the fly
to modify the output of the templated control. ASP.NET lends a helping hand with two techniques:
loading from file via the LoadTemplate method of the Page class and creating a prebuilt
class that implements the ITemplate interface. We discuss these techniques in the following
sections.
The Dynamic Templates Web Form
The Dynamic Templates web form demonstrates how to dynamically load templates into an
instance of the Repeater control built in this chapter. The Repeater control on the web form
looks like the typical Repeater bound to a SqlDataReader. The difference is the DropDownList
control that is used to select which template to apply to the Repeater control when it is loaded:
324 CHAPTER 7 ?–  SE RVER CONTROL DATA B INDING

FileTemplate.ascx
CustCodeTemplate
CustFileTemplate.ascx

The first two selections load the template from .ascx files that are present in the same
virtual directory as the web form. The default template is FileTemplate.ascx, as shown in
Figure 7-9.


Pages:
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438