MobilePage.AllowCustomAttributes Propriété

Définition

Obtient une valeur qui indique si les contrôles sur la page peuvent avoir des attributs personnalisés définis. La valeur par défaut est la valeur de l’attribut allowCustomAttributes de la section <mobilecontrols> du fichier Web.config. Cette API est obsolète. Pour plus d’informations sur le développement d’applications mobiles ASP.NET, consultez Applications mobiles & Sites avec 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

Valeur de propriété

true si les contrôles sur la page peuvent avoir des attributs personnalisés définis ; sinon, false.

Attributs

Exemples

L’exemple suivant montre comment utiliser la AllowCustomAttributes propriété pour activer l’attribut personnalisé AccessKey sur le Command.

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement si vous le copiez directement dans un fichier code-behind. Vous devez copier cet exemple de code dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations, consultez ASP.NET Web Forms Modèle de code de page.

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

Remarques

En plus de l’interface IAttributeAccessor , l’infrastructure de page ASP.NET fournit un CustomAttributes dictionnaire qui vous permet de spécifier des attributs supplémentaires, d’activer ou de désactiver des attributs personnalisés ou d’ajuster le comportement ou le rendu d’un contrôle. Pour activer ou désactiver l’attribution personnalisée, vous pouvez définir la AllowCustomAttributes propriété sur trueou définir l’attribut allowCustomAttributes de la <mobileControls> section de Web.config sur true.

Notes

Lorsque les attributs personnalisés sont activés, les erreurs typographiques dans les noms de propriétés peuvent être interprétées comme des attributs personnalisés. Par exemple, si un développeur spécifie incorrectement la Text propriété d’un contrôle en tant que « Txet », l’analyseur l’enregistre en tant qu’attribut personnalisé appelé « Txet » au lieu de lever une exception. Pour cette raison, les attributs personnalisés sont désactivés par défaut.

S’applique à

Voir aussi