Share via


Command.Click Événement

Définition

Se produit lorsqu'un utilisateur active un contrôle Command. 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:
 event EventHandler ^ Click;
public event EventHandler Click;
member this.Click : EventHandler 
Public Custom Event Click As EventHandler 

Type d'événement

Exemples

L’exemple de code suivant montre comment joindre des événements de commande. Cliquer sur l’un des Command boutons déclenche l’événement OnItemCommand . La fonction définie par l’utilisateur utilise l’argument CommandEventArgs pour voir sur quel Command bouton on a cliqué.

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations sur le modèle de code Web Forms, 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">
    //<Snippet3>
    public void Page_Load(Object sender, EventArgs e)
    {
        MobileCapabilities caps
            = (MobileCapabilities)Request.Browser;
        if (caps.MaximumSoftkeyLabelLength == 5)
        {
            Command1.SoftkeyLabel = "Click";
        }
        else if (caps.MaximumSoftkeyLabelLength > 5)
        {
            Command1.SoftkeyLabel = "Submit";
        }
    }
    //</Snippet3>

    void Command_Click(object sender, CommandEventArgs e)
    {
        string txt = "You clicked Button{0}. ({1} points)";
        if (e.CommandName.ToString() == "Command1")
        {
            Label1.Text = String.Format(txt, 1, 
                e.CommandArgument);
        }
        else if (e.CommandName.ToString() == "Command2")
        {
            Label1.Text = String.Format(txt, 2, 
                e.CommandArgument);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server">
            Click a button
        </mobile:Label>
        <mobile:Label id="Label2" runat="server" /> 
        <mobile:Command id="Command1"  Format="Button"
            OnItemCommand="Command_Click" 
            CommandName="Command1" runat="server" 
            Text="Button1" CommandArgument="70" />
        <mobile:Command id="Command2" Format="Link"
            OnItemCommand="Command_Click" 
            CommandName="Command2" runat="server" 
            Text="Button2" CommandArgument="50" />
    </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">
    '<Snippet3>
    Public Sub Page_Load(ByVal sender As Object, _
        ByVal e As EventArgs)

        Dim caps As System.Web.Mobile.MobileCapabilities _
            = CType(Request.Browser, MobileCapabilities)

        If caps.MaximumSoftkeyLabelLength = 5 Then
            Command1.SoftkeyLabel = "Click"
        ElseIf caps.MaximumSoftkeyLabelLength > 5 Then
            Command1.SoftkeyLabel = "Submit"
        End If
    End Sub
    '</Snippet3>

    Private Sub Command_Click(ByVal sender As Object, _
        ByVal e As CommandEventArgs)

        Dim txt As String = "You clicked Button{0}. ({1} points)"
        If e.CommandName.ToString() = "Command1" Then
            Label1.Text = String.Format(txt, 1, e.CommandArgument)
        ElseIf e.CommandName.ToString() = "Command2" Then
            Label1.Text = String.Format(txt, 2, e.CommandArgument)
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server">
            Click a button
        </mobile:Label>
        <mobile:Label id="Label2" runat="server" /> 
        <mobile:Command id="Command1" Format="Button"
            OnItemCommand="Command_Click" 
            CommandName="Command1" runat="server" 
            Text="Button1" CommandArgument="70" />
        <mobile:Command id="Command2" Format="Link"
            OnItemCommand="Command_Click" 
            CommandName="Command2" runat="server" 
            Text="Button2" CommandArgument="50" />
    </mobile:form>
</body>
</html>

Remarques

Lorsqu’un Command contrôle est activé, il déclenche l’événement OnClick . Pour plus d’informations, consultez les sections « Rendu spécifique à l’appareil » et « Comportement spécifique à l’appareil » dans System.Web.UI.MobileControls.Command.

S’applique à

Voir aussi