DeviceSpecificChoice 類別

定義

警告

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.

提供 DeviceSpecific/Choice 建構內的單一選項。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

public ref class DeviceSpecificChoice : System::Web::UI::IAttributeAccessor, System::Web::UI::IParserAccessor
[System.Web.UI.MobileControls.PersistName("Choice")]
public class DeviceSpecificChoice : System.Web.UI.IAttributeAccessor, System.Web.UI.IParserAccessor
[System.Web.UI.MobileControls.PersistName("Choice")]
[System.Obsolete("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.")]
public class DeviceSpecificChoice : System.Web.UI.IAttributeAccessor, System.Web.UI.IParserAccessor
[<System.Web.UI.MobileControls.PersistName("Choice")>]
type DeviceSpecificChoice = class
    interface IParserAccessor
    interface IAttributeAccessor
[<System.Web.UI.MobileControls.PersistName("Choice")>]
[<System.Obsolete("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.")>]
type DeviceSpecificChoice = class
    interface IParserAccessor
    interface IAttributeAccessor
Public Class DeviceSpecificChoice
Implements IAttributeAccessor, IParserAccessor
繼承
DeviceSpecificChoice
屬性
實作

範例

下列程式代碼範例顯示 <Choice> 影像內的專案。 屬性 SourceImageUrl 覆寫 控件的 Image 屬性。

雖然此範例使用函式來判斷瀏覽器是否需要 WML () isWML11 或支援色彩 () supportsColor ,但您可以改用 Web.config 檔案來定義 <DeviceSpecific> .NET Framework 自動用來判斷您的專案。

注意

下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到擴展名為 .aspx 的空白文字檔中。 如需詳細資訊,請參閱頁面語法概觀 ASP.NET Web Forms

<%@ 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>
<%@ 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>

備註

這個類別類似於 <Choice> 元素。 選項會依其出現在 DeviceSpecific> 元素內<的順序進行測試。 如果您指定 Filter 項目的 <Choice> 屬性,其值必須是 Machine.config 檔案區段中定義的 <deviceFilters> 裝置篩選名稱。 在運行時間,ASP.NET 根據目前裝置的功能評估指定的裝置篩選。 如果成功,則會選取選擇。 如果您未指定 Filter 屬性,則會選取項目的 <Choice> 預設值。

建構函式

DeviceSpecificChoice()
已淘汰.

初始化 DeviceSpecificChoice 類別的新執行個體。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

屬性

Argument
已淘汰.

取得或設定用於 Filter 屬性的引數。 預設值是 null。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

Contents
已淘汰.

取得針對 DeviceSpecific/Choice 建構的選項所定義的覆寫屬性。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

Filter
已淘汰.

取得或設定裝置篩選條件的名稱。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

HasTemplates
已淘汰.

取得值,指出 DeviceSpecific> 元素中<目前選取的選擇是否在其內定義範本。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

Templates
已淘汰.

取得已定義於 Choice> 元素中的<範本。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

Xmlns
已淘汰.

取得或設定 Choice> 專案中的標記<類型。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

方法

AddParsedSubObject(Object)
已淘汰.

Object 加入至 DeviceSpecificChoice 物件的 Templates 物件。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

Equals(Object)
已淘汰.

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetAttribute(String)
已淘汰.

DeviceSpecificChoice 物件中傳回指定的屬性。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

GetHashCode()
已淘汰.

做為預設雜湊函式。

(繼承來源 Object)
GetType()
已淘汰.

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()
已淘汰.

建立目前 Object 的淺層複製。

(繼承來源 Object)
SetAttribute(String, String)
已淘汰.

將指定的值指派給索引鍵所指定的屬性。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

ToString()
已淘汰.

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IAttributeAccessor.GetAttribute(String)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

已淘汰.

如需這個成員的說明,請參閱 GetAttribute(String)。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

IAttributeAccessor.SetAttribute(String, String)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

已淘汰.

如需這個成員的說明,請參閱 SetAttribute(String, String)。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

IParserAccessor.AddParsedSubObject(Object)
已淘汰.

如需這個成員的說明,請參閱 AddParsedSubObject(Object)。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

適用於

另請參閱