共用方式為


DeviceSpecificChoice 類別

提供 DeviceSpecific/Choice 建構內的單一選項。

命名空間: System.Web.UI.MobileControls
組件: System.Web.Mobile (在 system.web.mobile.dll 中)

語法

'宣告
Public Class DeviceSpecificChoice
    Implements IParserAccessor, IAttributeAccessor
'用途
Dim instance As DeviceSpecificChoice
public class DeviceSpecificChoice : IParserAccessor, IAttributeAccessor
public ref class DeviceSpecificChoice : IParserAccessor, IAttributeAccessor
public class DeviceSpecificChoice implements IParserAccessor, IAttributeAccessor
public class DeviceSpecificChoice implements IParserAccessor, IAttributeAccessor

備註

這個類別 (Class) 類似 <Choice> 項目。選項會以其出現在 <DeviceSpecific> 項目內的順序來進行測試。如果您指定 <Choice> 項目的 Filter 屬性,其值必須是 Machine.config 檔的 <deviceFilters> 區段所定義之裝置篩選條件的名稱。在執行階段,ASP.NET 會針對目前裝置的功能來評估指定的裝置篩選條件。若通過評估,則會選取該選項。如果您不指定 Filter 屬性,則會選取 <Choice> 項目的預設值。

範例

下列程式碼範例顯示影像中的 <Choice> 項目。Source 屬性 (Attribute) 會覆寫 Image 控制項的 ImageUrl 屬性 (Property)。

雖然範例使用函式來決定瀏覽器是否需要 WML (isWML11) 或支援色彩 (supportsColor),但是您可以改用 Web.config 檔來定義 <DeviceSpecific> 項目,進而 .NET Framework 會自動使用該項目來為您做出決定。

<deviceFilters>
  <filter name="isWML11" 
          compare="PreferredRenderingType" 
          argument="wml11" />
  <filter name="supportsColor" 
          compare="IsColor" 
          argument="true" />
</deviceFilters>
Note注意事項

以下程式碼範例使用單一檔案程式碼模型,如果直接複製到程式碼後置 (Code-Behind) 檔案即可能無法作用。這個程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。如需詳細資訊,請參閱 ASP.NET Web 網頁程式碼模型

<%@ 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>
<%@ 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 安全性

繼承階層架構

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

執行緒安全

這個型別的所有公用靜態成員 (即 Visual Basic 中的 Shared 成員) 都是安全執行緒。並非所有的執行個體成員均為安全執行緒。

平台

Windows 98、 Windows 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

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1

請參閱

參考

DeviceSpecificChoice 成員
System.Web.UI.MobileControls 命名空間

其他資源

DeviceSpecific 控制項簡介
<Choice> 項目 (.NET Framework 開發人員手冊)
<DeviceSpecific> 項目