This documentation is archived and is not being maintained.

DeviceSpecificChoice Class

Provides a single choice within a DeviceSpecific/Choice construct.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DeviceSpecificChoice : IParserAccessor, 

This class is analogous to the <Choice> element. Choices are tested in the order that they appear within a <DeviceSpecific> element. If you specify the Filter property of the <Choice> element, its value must be the name of a device filter defined in the <deviceFilters> section of the Machine.config file. At run time, ASP.NET evaluates the specified device filter against the capabilities of the current device. If successful, the choice is selected. If you do not specify the Filter property, the defaults for the <Choice> element are selected.

The following code example shows a <Choice> element within an image. The Source attribute overrides the ImageUrl property of the Image control.

Although the example uses functions to determine whether the browser requires WML (isWML11) or supports color (supportsColor), you can instead use a Web.config file to define a <DeviceSpecific> element that the .NET Framework automatically uses to make the determination for you.

  <filter name="isWML11" 
          argument="wml11" />
  <filter name="supportsColor" 
          argument="true" />

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Syntax Overview.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
    private bool supportsColor(MobileCapabilities caps, string optValue)
        // Determine if the browser is not a Web crawler and 
        // can display in color 
        if (!caps.Crawler && caps.IsColor)
            return true;
        return false;

    private bool isWML11(MobileCapabilities caps, string optValue)
        // Determine if the browser is not a Web crawler and 
        // requires WML markup 
        if (!caps.Crawler && caps.PreferredRenderingType ==
            return true;
        return false;

<html xmlns="" >
    <mobile:form id="form1" runat="server">
        <mobile:Image ID="Image1" runat="server" 
            AlternateText="Cannot display this image.">
                <choice Filter ="isWML11" ImageURL="wmlImage.wbmp" />
                <choice Filter="supportsColor" ImageURL="colorImage.gif" />
                <choice ImageURL="monoImg.gif" />


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1