MobilePage.AllowCustomAttributes 属性
定义
获取一个值,该值指示是否可以为页上的控件定义自定义属性。Gets a value indicating whether controls on the page can have custom attributes defined. 默认值是 Web.config 文件的 <mobilecontrols> 部分的 allowCustomAttributes 特性的值。The default value is the value of the allowCustomAttributes attribute of the <mobilecontrols> section of the Web.config file. 此 API 已废弃不用。This API is obsolete. 若要了解如何开发 ASP.NET 移动应用,请参阅 Mobile Apps & Sites with ASP.NET (ASP.NET 移动应用和网站)。For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.
public:
property bool AllowCustomAttributes { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(false)]
[System.ComponentModel.Browsable(false)]
public bool AllowCustomAttributes { get; set; }
[<System.ComponentModel.Bindable(false)>]
[<System.ComponentModel.Browsable(false)>]
member this.AllowCustomAttributes : bool with get, set
Public Property AllowCustomAttributes As Boolean
属性值
如果可以为页上的控件定义自定义特性,则为 true;否则为 false。true if the controls on the page can have custom attributes defined; otherwise, false.
- 属性
示例
下面的示例演示如何使用 AllowCustomAttributes 属性来启用上的自定义 AccessKey 特性 Command 。The following example demonstrates how to use the AllowCustomAttributes property to enable the custom AccessKey attribute on the Command.
备注
下面的代码示例使用单文件代码模型,并且如果将其直接复制到代码隐藏文件中,可能无法正常工作。The following code sample uses the single-file code model and may not work correctly if you copy it directly into a code-behind file. 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。You must copy this code sample into an empty text file that has an .aspx extension. 有关详细信息,请参阅 ASP.NET Web 窗体页代码模型。For more information, see ASP.NET Web Forms Page Code Model.
<%@ 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">
// <Snippet2>
private void Command_OnClick(object sender, EventArgs e)
{
// Display the other form
if (ActiveForm.ID == "Form1")
ActiveForm = Form2;
else
ActiveForm = Form1;
}
// </Snippet2>
public bool isAccessKey(MobileCapabilities caps,
string optValue)
{
// Determine if the browser is not a Web crawler
// and can use access keys
if (!caps.Crawler && caps.SupportsAccesskeyAttribute)
return true;
return false;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:Form runat="server" id="Form1" >
<mobile:Label Runat="server">This is Form1</mobile:Label>
<mobile:Command id="cmd1" runat="server" Text="No AccessKey"
onClick="Command_OnClick">
<DeviceSpecific>
<Choice Filter="isAccessKey" Text="AccessKey is 1"/>
</DeviceSpecific>
</mobile:Command>
<mobile:Label id="Label1" runat="server" />
</mobile:Form>
<mobile:Form ID="Form2" Runat="server">
<mobile:Label Runat="server">This is Form2</mobile:Label>
<mobile:Command id="cmd2" runat="server" text="Back to Form1"
onClick="Command_OnClick">
<DeviceSpecific>
<Choice Filter="isAccessKey" Text="1 is AccessKey" AccessKey="1" />
</DeviceSpecific>
</mobile:Command>
</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">
' <Snippet2>
Private Sub Command_OnClick(ByVal sender As Object, ByVal e As EventArgs)
' Display the other form
If ActiveForm.ID = "Form1" Then
ActiveForm = Form2
Else
ActiveForm = Form1
End If
End Sub
' </Snippet2>
Public Function isAccessKey(ByVal caps As MobileCapabilities, _
ByVal optValue As String) As Boolean
' Determine if the browser is not a Web crawler
' and can use access keys
If Not caps.Crawler AndAlso caps.SupportsAccesskeyAttribute Then
Return True
End If
Return False
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:Form runat="server" id="Form1" >
<mobile:Label ID="Label1" Runat="server">This is Form1</mobile:Label>
<mobile:Command id="cmd1" runat="server" Text="No AccessKey"
onClick="Command_OnClick">
<DeviceSpecific>
<Choice Filter="isAccessKey" Text="AccessKey is 1"/>
</DeviceSpecific>
</mobile:Command>
<mobile:Label id="Label2" runat="server" />
</mobile:Form>
<mobile:Form ID="Form2" Runat="server">
<mobile:Label ID="Label3" Runat="server">This is Form2</mobile:Label>
<mobile:Command id="cmd2" runat="server" text="Back to Form1"
onClick="Command_OnClick">
<DeviceSpecific>
<Choice Filter="isAccessKey" Text="1 is AccessKey" AccessKey="1" />
</DeviceSpecific>
</mobile:Command>
</mobile:Form>
</body>
</html>
注解
除了 IAttributeAccessor 接口外,ASP.NET 页框架还提供了一个 CustomAttributes 字典,该字典允许您指定其他特性、启用或禁用自定义特性化或调整控件的行为或呈现。In addition to the IAttributeAccessor interface, the ASP.NET page framework provides a CustomAttributes dictionary that allows you to specify additional attributes, enable or disable custom attributing, or adjust a control's behavior or rendering. 若要启用或禁用自定义特性设置,可以将 AllowCustomAttributes 属性设置为 true ,也可以将 allowCustomAttributes Web.config 的节的特性设置 <mobileControls> 为 true 。To enable or disable custom attributing, you can either set the AllowCustomAttributes property to true, or you can set the allowCustomAttributes attribute of the <mobileControls> section of Web.config to true.
备注
启用自定义属性后,属性名称中的版式错误可解释为自定义属性。When custom attributes are enabled, typographic errors in property names can be interpreted as custom attributes. 例如,如果开发人员错误地将 Text 控件的属性指定为 "Txet",则分析器会将其另存为一个名为 "Txet" 的自定义特性,而不是引发异常。For example, if a developer incorrectly specifies the Text property of a control as "Txet", the parser would save it as a custom attribute called "Txet" instead of raising an exception. 出于此原因,自定义属性默认情况下处于禁用状态。For this reason, custom attributes are disabled by default.