MobilePage.AllowCustomAttributes Propiedad

Definición

Obtiene un valor que indica si los controles de la página puede tener definidos atributos personalizados. El valor predeterminado es el valor del atributo allowCustomAttributes de la sección <mobilecontrols> del archivo Web.config. Esta API está obsoleta. Para obtener información sobre cómo desarrollar aplicaciones móviles ASP.NET, consulte 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

Valor de propiedad

Es true si los controles de la página pueden tener definidos atributos personalizados; de lo contrario, es false.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo usar la AllowCustomAttributes propiedad para habilitar el atributo personalizado AccessKey en .Command

Nota:

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Debe copiar este ejemplo de código en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información, consulte ASP.NET Web Forms modelo de código de página.

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

Comentarios

Además de la IAttributeAccessor interfaz , el marco de ASP.NET página proporciona un CustomAttributes diccionario que permite especificar atributos adicionales, habilitar o deshabilitar la atribución personalizada, o ajustar el comportamiento o la representación de un control. Para habilitar o deshabilitar la asignación personalizada, puede establecer la AllowCustomAttributes propiedad en o puede establecer el allowCustomAttributes atributo de la <mobileControls> sección de Web.config en truetrue.

Nota

Cuando los atributos personalizados están habilitados, los errores tipográficos en los nombres de propiedad se pueden interpretar como atributos personalizados. Por ejemplo, si un desarrollador especifica incorrectamente la Text propiedad de un control como "Txet", el analizador lo guardaría como un atributo personalizado denominado "Txet" en lugar de generar una excepción. Por este motivo, los atributos personalizados están deshabilitados de forma predeterminada.

Se aplica a

Consulte también