Command クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)


Command コントロールは、要求側デバイス上に対話型 UI 要素として表示されます。UI 要素のラベルは、Text プロパティから得られます。このプロパティは、TextControl 基本クラスから継承されたものです。
![]() |
---|
ASP.NET モバイル Web ページの URL には特殊文字を使用しないでください。Command イベントをサーバーにポストバックするために生成される HREF タグは、厳密に検証されません。たとえば、URL に空白が含まれていると、一部の WML ブラウザで処理できない WML が生成される場合があります。 |

コマンド イベントを追加する方法を次のコード例に示します。Command ボタンのいずれかをクリックすると、OnItemCommand イベントが発生します。ユーザー定義関数は、CommandEventArgs 引数を使用して、クリックされた Command ボタンを確認します。
![]() |
---|
次のコード例はシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード例は、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ 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 > <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="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"> 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"; } } 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 > <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>


System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.TextControl
System.Web.UI.MobileControls.Command


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Command クラスのページへのリンク