DeviceSpecificChoice Class
Assembly: System.Web.Mobile (in system.web.mobile.dll)
'Declaration Public Class DeviceSpecificChoice Implements IParserAccessor, IAttributeAccessor 'Usage Dim instance As DeviceSpecificChoice
public class DeviceSpecificChoice implements IParserAccessor, IAttributeAccessor
public class DeviceSpecificChoice implements IParserAccessor, IAttributeAccessor
Not applicable.
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>
Note: |
|---|
| 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="VB" 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 Function supportsColor(ByVal caps As MobileCapabilities, _ ByVal value As String) As Boolean ' Determine if the browser is not a Web crawler and ' can display in color If Not caps.Crawler And caps.IsColor Then Return True Else Return False End If End Function Private Function isWML11(ByVal caps As MobileCapabilities, _ ByVal value As String) As Boolean ' Determine if the browser is not a Web crawler and ' requires WML markup If (Not caps.Crawler) AndAlso caps.PreferredRenderingType = _ MobileCapabilities.PreferredRenderingTypeWml11 Then Return True Else Return False End If End Function </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>
- AspNetHostingPermission For operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission For operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: