Classe Command

Consente di creare un elemento di interfaccia utente che consente all'utente di richiamare gestori eventi ASP.NET e fornisce uno strumento per inviare input utente dagli elementi di interfaccia utente al server.

public class System.Web.UI.MobileControls.Command : 
   System.Web.UI.MobileControls.TextControl,
   System.Web.UI.IPostBackEventHandler

Osservazioni

Il controllo Command viene visualizzato come un elemento interattivo di interfaccia utente sul dispositivo che lo richiede. L'etichetta dell'elemento di interfaccia utente è derivato dalla proprietà Text, ereditata dalla classe base TextControl.

**Attenzione   **È consigliabile evitare l'uso di caratteri speciali negli URL delle pagine Web mobili ASP.NET. I tag HREF generati per l'invio di eventi Command al server non vengono convalidati in maniera efficace. Un URL che include spazi, ad esempio, determina la creazione di WML che non può essere gestito da alcuni browser WML.

Esempio

L'esempio di codice che segue dimostra il modo in cui allegare eventi di comando. Facendo clic su uno dei pulsanti Command viene generato l'evento OnItemCommand. La funzione definita dall'utente utilizza l'argomento CommandEventArgs per individuare il pulsante Command selezionato.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script Language="VB" runat=server>

Sub Command_Click(sender As Object, e As CommandEventArgs)
   If e.CommandName.ToString() = "Command1" Then
      Label1.Text = "You clicked Button1."
   Else If e.CommandName.ToString() = "Command2" Then
      Label1.Text = "You clicked Button2."
   End If  
End Sub
</script>

<mobile:Form id="myForm" runat=server>
   <mobile:Label id="Label1" runat=server>Click a button
      </mobile:label> 
   <mobile:Label id="Label2" runat=server></mobile:label> 
   <mobile:Command id="Command1" OnItemCommand="Command_Click" 
      CommandName="Command1" runat="server" Text="Button1" />
   <mobile:Command id="Command2" OnItemCommand="Command_Click"
      CommandName="Command2" runat="server" Text="Button2" />
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

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

void Command_Click(object sender, CommandEventArgs e)
{
   if (e.CommandName.ToString()=="Command1")
   {
      Label1.Text = "You clicked Button1.";
   }
   else if (e.CommandName.ToString()=="Command2")
   {
      Label1.Text = "You clicked Button2.";
   }  
}
</script>

<mobile:Form id="myForm" runat=server>
   <mobile:Label id="Label1" runat=server>Click a button
      </mobile:label> 
   <mobile:Label id="Label2" runat=server></mobile:label> 
   <mobile:Command id="Command1" OnItemCommand="Command_Click" 
      CommandName="Command1" runat="server" Text="Button1" />
   <mobile:Command id="Command2" OnItemCommand="Command_Click"
      CommandName="Command2" runat="server" Text="Button2" />
</mobile:Form>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

Vedere anche

Controllo Command