Export (0) Print
Expand All

MobilePage.AllowCustomAttributes Property

Gets a value indicating whether controls on the page can have custom attributes defined. The default value is the value of the allowCustomAttributes attribute of the <mobilecontrols> section of the Web.config file. This API is obsolete. For information about how to develop ASP.NET mobile applications, see the www.asp.net/mobile Web site.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

[BindableAttribute(false)]
[BrowsableAttribute(false)]
public bool AllowCustomAttributes { get; set; }
<asp:MobilePage AllowCustomAttributes="True|False" />

Property Value

Type: System.Boolean
true if the controls on the page can have custom attributes defined; otherwise, false.

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. 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.

NoteNote

When custom attributes are enabled, typographic errors in property names can be interpreted as custom attributes. 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.

The following example demonstrates how to use the AllowCustomAttributes property to enable the custom AccessKey attribute on the Command.

NoteNote

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. You must copy this code sample into an empty text file that has an .aspx extension. 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">
    private void Command_OnClick(object sender, EventArgs e)
    {
        // Display the other form
        if (ActiveForm.ID == "Form1")
            ActiveForm = Form2;
        else
            ActiveForm = Form1;
    }

    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>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft