Export (0) Print
Expand All

DeviceSpecificChoice Class

Note: This API is now obsolete.

Provides a single choice within a DeviceSpecific/Choice construct. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.

System.Object
  System.Web.UI.MobileControls.DeviceSpecificChoice

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

[PersistNameAttribute("Choice")]
[ObsoleteAttribute("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DeviceSpecificChoice : IParserAccessor, 
	IAttributeAccessor

The DeviceSpecificChoice type exposes the following members.

  NameDescription
Public methodDeviceSpecificChoiceInitializes a new instance of the DeviceSpecificChoice class. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Top

  NameDescription
Public propertyArgumentGets or sets the argument used for a Filter property. The default value is null. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public propertyContentsGets the overridden properties defined for a choice in a DeviceSpecific/Choice construct. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public propertyFilterGets or sets the name of a device filter. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public propertyHasTemplatesGets a value indicating whether the currently selected choice in the <DeviceSpecific> element has templates defined within it. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public propertyTemplatesGets the templates that have been defined in the <Choice> element. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public propertyXmlnsGets or sets the type of markup in a <Choice> element. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Top

  NameDescription
Protected methodAddParsedSubObjectAdds the Object to the DeviceSpecificChoice object's Templates object. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodGetAttributeReturns the specified attribute from the DeviceSpecificChoice object. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSetAttributeAssigns the given value to the attribute specified by the key. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIAttributeAccessor.GetAttributeInfrastructure. For a description of this member, see IAttributeAccessor.GetAttribute. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Explicit interface implemetationPrivate methodIAttributeAccessor.SetAttributeInfrastructure. For a description of this member, see IAttributeAccessor.SetAttribute. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Explicit interface implemetationPrivate methodIParserAccessor.AddParsedSubObjectInfrastructure. For a description of this member, see IParserAccessor.AddParsedSubObject. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.
Top

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.


<deviceFilters>
  <filter name="isWML11" 
          compare="PreferredRenderingType" 
          argument="wml11" />
  <filter name="supportsColor" 
          compare="IsColor" 
          argument="true" />
</deviceFilters>


NoteNote

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" 
    Namespace="System.Web.UI.MobileControls" 
    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 ==
            MobileCapabilities.PreferredRenderingTypeWml11)
            return true;
        return false;
    }
</script>

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


.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1
Obsolete (compiler warning) in 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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

Community Additions

ADD
Show:
© 2014 Microsoft