Introducing Control Templates
You typically use templates to alter or enrich the appearance of ASP.NET mobile controls. For example, you can enhance the appearance of the List control by defining a header or footer template. Templates are composed of markup language elements (HTML or WML tags, for example) and server controls.
Every template for a control is associated with a device filter. Whenever the device filter evaluates to true, the application displays the contents of the template. Some controls contain one template per device filter. If a control has more than one template per device filter, the control is said to contain a template set. For instance, the List control can have header, footer, item, alternating item, and separator templates. These five templates make up the List control's template set.
Because controls support multiple device filters, it is possible to define many template sets for a control. For a list of available templates, see How to: Create and Edit Templates.
Note that templates differ from styles. Templates define content and controls to be displayed. The application renders them when it renders the controls to which they are attached. However, styles specify the appearance of content and controls. Your application can use styles without using templates. It can also apply styles to the mobile controls that you define within templates.
For example, an application might use one or more styles to set the color and font within a List control's layout. The List control might also have one or more templates attached to it that contain additional text and controls. The application displays text and controls in the template using the specified styles whenever it renders the List control.
Applications also use templates to customize the appearance of controls for specific types of hardware. Templates for a mobile control are defined for a particular device filter. At run time, the application uses the templates that belong to a particular filter to override the default rendering of the control whenever the device filter evaluates to true.
In addition, ASP.NET mobile controls enable applications to contain device-independent templates. For more information, see Template Sets and Templated Controls.
Editing Templates in Source View
In Visual Studio, you can edit templates directly in Source view. However, Design view requires well-formed HTML within each template. For example, inserting
<table> into a header template and
</table> into a footer template results in Design view being unable to render the templates because neither template has a complete table. In template editing mode, Design view will display an error message indicating that the HTML is not well formed. In these cases, you can still edit the template in Source view, and the page will render correctly.