Configuring a Web Application for Multiple Devices

Although ASP.NET mobile Web Forms pages are capable of rendering automatically to a variety of mobile devices, you can insert rendering and handling that are specific to a device or class of devices. A device filter can be used to target a particular subset of devices. It does this by specifying a selection criteria based on capabilities of the device. Device filters added in the ASP.NET Mobile Designer are stored in the <deviceFilters> section in the Web.config configuration file. You can list common filters in Web.config and refer to them by name anywhere in the application.

**Note   **Device filters are case-sensitive. A filter named isColor is different from a filter named IsColor.

After a device filter is defined, you can apply it in a specific ASP.NET mobile control to define device-specific rendering. Applied device filters map to <Choice> element tags inside DeviceSpecific constructs, in the .aspx file. You can then set up property overrides and templating for these specific applied device filters. Some examples of device-specific customizations include:

  • Overriding properties of controls, such as choosing different images for an Image control based on display capabilities.
  • Using different rendering styles for different mobile devices.
  • Using templates for richer rendering on devices such as the Pocket PC.

Each of these scenarios requires filtering based on whether the target device matches a <deviceFilters> section in Web.config. These filters also might appear throughout the application, rather than in a single place.

For more information, refer to Device Filtering Recommendations.

The next sections explain the specific types of device-independent content: device templates and overriding properties.

Device Templates

All mobile controls have a default look and layout for a specific device and markup. You can manipulate the look and layout by setting properties or by using styles. Some controls also allow you to customize their look by using templates.

A template is a set of markup language (for example, HTML, cHTML, or WML) elements and controls that make up the layout for a particular portion of a control. For example, in the List control, you can define a header or footer template, among others. You can also define a template to format each list item, and you can format a different template for each alternating list item.

Note   Templates differ from styles. Styles specify the appearance of elements such as color, font, and so on within a control's layout. You can use styles without using templates, if all you want to do is change the appearance of the default layout of a control. You can also use styles with a template to control the appearance of elements that you define within your templates.

Templates consist of markup language and embedded controls. When the control runs in the mobile Web Forms page, the ASP.NET page framework renders the contents of the template in place of the default code for the control. For further information about mixing device-specific markup languages with mobile controls, see Using Device-Specific Templates.

Some controls allow multiple sets of templates through the <DeviceSpecific> and <Choice> tags. These multiple sets of templates are called template sets.

Overriding Properties

Your mobile Web application might require mobile control properties to be set differently depending on the target device. For example, you might want a Label control to have longer text on one set of devices, and more abbreviated text on another. For each control, a set of properties can be overridden on a per-device basis.

Note   To set property overrides, you must first define device filters. Use these filters to pinpoint the set of mobile devices for which you want to define custom property values.

See Also

Custom Attributes | Device Filtering Recommendations | HasCapability Method | Device Evaluation Methods | Extended Browser Capabilities | MobileControl | Understanding the Data Mapping Rules for the Configuration Provider