Evento ItemCommand (Command)

Si verifica quando l'utente sceglie un comando associato a un controllo Command.

public event CommandEventHandler ItemCommand

Osservazioni

Quando viene definito un gestore eventi ItemCommand, il controllo Command notifica al gestore la creazione di un evento di elemento dovuta all'interazione con l'utente. A differenza dell'evento Click, l'evento ItemCommand viene passato tramite bubbling ai controlli padre.

Il rendering dell'evento ItemCommand è specifico del dispositivo ed è illustrato in dettaglio nella sezione dedicata al controllo Command relativa al funzionamento specifico del dispositivo.

L'evento OnItemCommand viene generato dopo un evento OnClick. In uno scenario in cui si ripete lo stesso insieme di azioni ogni volta in cui si fa clic su un pulsante di comando, è possibile utilizzare la proprietà CommandName o la proprietà CommandArgument del controllo Command per identificare il pulsante di comando scelto dall'utente.

Esempio

Nell'esempio riportato di seguito viene mostrato come rilevare eventi ItemCommand per più comandi.

<script language="vb" runat=server>

Sub cmd_OnItemCommand(sender As Object, e As CommandEventArgs)
   ' Use the value of the CommandName property to find
   ' a command button that has been clicked.
   message1.Text = "Today's quote of " + e.CommandName + _ 
   " is " + e.CommandArgument   

   message2.Text = "Yesterday's quote of " + e.CommandName + _
   " was " + (Convert.ToInt32(e.CommandArgument)-5)
End Sub

</script>

<mobile:form id="myForm" runat=server>
   <mobile:label id="message1" runat=server>Click the button for
      quotes</mobile:label> 
   <mobile:label id="message2" runat=server></mobile:label> 
   <mobile:command id="CmdA" onItemCommand ="cmd_OnItemCommand"
      CommandArgument="70" CommandName="ca" 
      runat="server" Text="Company A" />
   <mobile:command id="CmdB" onItemCommand ="cmd_OnItemCommand"
      CommandArgument="25" CommandName="cb" 
      runat="server" Text="Company B" />
   <mobile:command id="CmdC" OnItemCommand ="cmd_OnItemCommand"
      CommandArgument="110" CommandName="cc" 
      runat="server" Text= "Company C" />
</mobile:form>
[C#]

<script language="c#" runat=server>

void cmd_OnItemCommand(object sender, CommandEventArgs e)
{
   // Use the value of the CommandName property to find
   // a command button that has been clicked.
   message1.Text = "Today's quote of " + e.CommandName + 
   " is " + e.CommandArgument;   

   message2.Text = "Yesterday's quote of " + e.CommandName +
   " was " + (Convert.ToInt32(e.CommandArgument)-5);
}

</script>

<mobile:form id="myForm" runat=server>
   <mobile:label id="message1" runat=server>Click the button for
      quotes</mobile:label> 
   <mobile:label id="message2" runat=server></mobile:label> 
   <mobile:command id="CmdA" onItemCommand ="cmd_OnItemCommand"
      CommandArgument="70" CommandName="ca" 
      runat="server" Text="Company A" />
   <mobile:command id="CmdB" onItemCommand ="cmd_OnItemCommand"
      CommandArgument="25" CommandName="cb" 
      runat="server" Text="Company B" />
   <mobile:command id="CmdC" OnItemCommand ="cmd_OnItemCommand"
      CommandArgument="110" CommandName="cc" 
      runat="server" Text= "Company C" />
</mobile:form>

Vedere anche

Evento ItemCommand (List) | Classe ListCommandEventArgs | Evento ItemCommand (ObjectList) | Classe ObjectListCommandEventArgs | Metodo OnItemCommand | Classe Command