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.
Assembly: System.Web.Mobile (in System.Web.Mobile.dll)
'Declaration <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class Command _ Inherits TextControl _ Implements IPostBackEventHandler, IPostBackDataHandler 'Usage Dim instance As Command
<mobile:Command />
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. |
| Topic | Location |
|---|---|
| Walkthrough: Creating Web Pages for Mobile Devices | Building ASP .NET Web Applications in Visual Studio |
The following code example 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.
Note: |
|---|
The following code example uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code example must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Code Model. |
<%@ 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"> 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 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>
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.TextControl
System.Web.UI.MobileControls.Command
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Caution: