Command Class

Creates a user interface element that enables users to invoke ASP.NET event handlers and it provides a means to post user input from UI elements back to the server.

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

Remarks

The Command control displays as an interactive UI element on the requesting device. The label of the UI element comes from the Text property, which is inherited from the TextControl base class.

**Caution   **Avoid using special characters in ASP.NET mobile Web page URLs. The HREF tags generated for posting Command events back to the server are not strictly validated. For example, a URL that includes spaces results in the generation of WML that cannot be handled by some WML browsers.

Example

The following code sample demonstrates how to attach command events. Clicking either of the Command buttons raises the OnItemCommand event. The user-defined function uses the CommandEventArgs argument to see which Command button was clicked.

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

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

Command Control