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 的网站

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> 图像中的元素。 特性 Source 替代 ImageUrl 控件的 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 的网站

属性

Argument
已过时.

获取或设置用于 Filter 属性的参数。 默认值是 null。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

Contents
已过时.

获取为 DeviceSpecific/Choice 构造中的选择定义的重写属性。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

Filter
已过时.

获取或设置设备筛选器的名称。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

HasTemplates
已过时.

获取一个值,该值指示 DeviceSpecific> 元素中<当前选择的选项是否具有在其中定义的模板。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

Templates
已过时.

获取已在 Choice> 元素中<定义的模板。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

Xmlns
已过时.

获取或设置 Choice> 元素中的<标记类型。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

方法

AddParsedSubObject(Object)
已过时.

Object 添加到 DeviceSpecificChoice 对象的 Templates 对象中。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

Equals(Object)
已过时.

确定指定对象是否等于当前对象。

(继承自 Object)
GetAttribute(String)
已过时.

DeviceSpecificChoice 对象返回指定的特性。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

GetHashCode()
已过时.

作为默认哈希函数。

(继承自 Object)
GetType()
已过时.

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()
已过时.

创建当前 Object 的浅表副本。

(继承自 Object)
SetAttribute(String, String)
已过时.

将给定的值分配给键指定的特性。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

ToString()
已过时.

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IAttributeAccessor.GetAttribute(String)

此 API 支持产品基础结构,不能在代码中直接使用。

已过时.

有关此成员的说明,请参见 GetAttribute(String)。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

IAttributeAccessor.SetAttribute(String, String)

此 API 支持产品基础结构,不能在代码中直接使用。

已过时.

有关此成员的说明,请参见 SetAttribute(String, String)。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

IParserAccessor.AddParsedSubObject(Object)
已过时.

有关此成员的说明,请参见 AddParsedSubObject(Object)。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

适用于

另请参阅