
Using the Device-Specific/Choice Construct
The <DeviceSpecific><Choice> construct is the core construct for inserting device-specific markup in a page. To add device-specific markup for a control, you add the <DeviceSpecific> element as a child of the control. A control may contain only one <DeviceSpecific> element.
The <DeviceSpecific> element and the <Choice> element enable you to specify a set of values from which ASP.NET chooses, based on characteristics of the requesting device. The values of the choices are strings.
The <DeviceSpecific> element is an outer container for holding a number of choices, as shown in the following example:
<mobile:Image runat=server ImageURL="bw.gif">
<DeviceSpecific>
<Choice Filter="isColor" ImageURL="colorImg.gif"
AlternateText="This device cannot display the image." />
<Choice Filter="isWML11" ImageURL="myImage.wbmp" />
<Choice ImageURL="monoImage.gif" />
</DeviceSpecific>
</mobile:Image>
Filters such as isColor must have corresponding entries in the Web.config file or must exist as methods on the page or user control, as described previously.
Using the Choice Element
Choices are placed inside a <DeviceSpecific> element, and represent device characteristic/value pairs, where the device characteristic is drawn from a number of sources. Choices are evaluated in the order that they appear in the DeviceSpecific/Choice construct.
Although a control can contain only one <DeviceSpecific> element, you can add any number of <Choice> elements within a <DeviceSpecific> element. Each <Choice> element can contain the following:
A filter name, which specifies the device filter to evaluate. If the filter name is omitted, the choice is selected by default.
Additional properties that override properties of the parent control.
Template definitions for the control.
ASP.NET selects the <Choice> element to use by going through each choice in order and evaluating the filter specified by the filter name. If the filter matches the current target device (by evaluating to true), that choice is selected. The control then applies any property overrides specified in the choice, and can use any templates defined in rendering.