[Wap]Command 控件

本文介绍了ASP.NET中Command控件的基本用法及其属性,包括如何处理用户输入并通过单击事件回发到服务器。提供了控件的使用示例,展示了如何在不同编程语言下设置控件属性。

Command 控件提供了一种从用户界面元素调用 ASP.NET 事件处理程序的方法,从而可以将用户输入从用户界面元素回发到服务器。Command 控件实现 IPostBackDataHandler 接口,因此它可以处理通过单击图像创建的回发事件。

移动控件语法
必需的属性、默认值和具有代码特征的元素以粗体显示。

<mobile:Command
   runat="server"
   id="id"
   Font-Name="fontName"
   Font-Size="{NotSet|Normal|Small|Large}"
   Font-Bold="{NotSet|False|True}"
   Font-Italic="{NotSet|False|True}"
   ForeColor="foregroundColor"
   BackColor="backgroundColor"
   Alignment="{NotSet|Left|Center|Right}"
   BreakAfter="{True|False}"
   EnableViewState="{True|False}"
   StyleReference="styleReference"
   Text="text"
   Visible="{True|False}"
   Wrapping="{NotSet|Wrap|NoWrap}"

   CausesValidation="{NotSet|False|True}"
   CommandArgument="commandArgument"
   CommandName="commandName"
   Format="Button|Link"
   ImageUrl="imageUrl"
   OnClick="clickEventHandler"
   OnItemCommand="commandEventHandler"
   SoftkeyLabel="softkeyLabel">
innerText
</mobile:Command>
包容规则
以下控件可以包含 Command 控件。

控件 说明
System.Web.UI.MobileControls.Form 可以包含任意多个 Command 控件。
System.Web.UI.MobileControls.Panel 可以包含任意多个 Command 控件。

文本控件不能包含任何其他控件。

设备模板
无。

特定于设备的行为
呈现命令的样式将根据设备的不同有所不同,但命令的文本将显示在所有设备上。您可以从所有设备调用 Command 控件。

设备语言 行为描述
HTML Command 控件作为按钮呈现为一个 <input> 标记,后接一个 <br/> 标记
如果同一个窗体上有多个命令并发生一个提交操作,则第一个命令将接收 Click 事件。但是,在某些 HTML 窗体上,ENTER 键无效。如果在具有 Command 控件的页上按 ENTER 键,则第一个命令将接收 Click 事件。
 
WML Command 控件以下面的格式生成 WML。
<anchor>TextProperty<go href="postbackinfo"/> </go></anchor>
<br/>
注意   您必须避免在 ASP.NET 移动 Web 窗体页 URL 中使用特殊字符。为将命令事件回发到服务器而生成的 HREF 标记未经严格验证。包含空格的 URL 导致所生成的 WML 不能被某些 WML 浏览器处理。
在某些情况下(例如窗体提交),Command 控件以 <do> 元素而不是定位点的形式呈现给 WML。在这些情况下,将忽略 FontSize、FontStyle 和 Wrapping 属性。
 

示例
下面的示例使用两个标签,每个窗体上使用一个。第一个标签未进行修改,因此不需要 ID 值。第二个标签的 ID 值是 WelcomeMessage,在 Button_OnClick 事件处理程序中设置其文本值。

[Visual Basic]
<%@ 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">
protected Sub Button_OnClick(sender As Object, e As EventArgs) 
   WelcomeMessage.Text 
= "Welcome to my app, " + NameEdit.Text
   ActiveForm 
= SecondPanel
End Sub

</script>

<mobile:Form runat="server">
   
<mobile:Label runat="server">Enter your name</mobile:Label>
   
<mobile:TextBox runat="server" id="NameEdit" />
   
<mobile:Command runat="server" id="Button" OnClick="Button_OnClick">
      OK
   
</mobile:Command>
</mobile:Form>

<mobile:Form runat="server" id="SecondPanel">
   
<mobile:Label runat="server" id="WelcomeMessage" />
</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">
protected void Button_OnClick(Object sender, EventArgs e) 
{
   WelcomeMessage.Text 
= "Welcome to my app, " + NameEdit.Text;
   ActiveForm 
= SecondPanel;
}

</script>

<mobile:Form runat="server">
   
<mobile:Label runat="server">Enter your name</mobile:Label>
   
<mobile:TextBox runat="server" id="NameEdit" />
   
<mobile:Command runat="server" id="Button" OnClick="Button_OnClick">
      OK
   
</mobile:Command>
</mobile:Form>

<mobile:Form runat="server" id="SecondPanel">
   
<mobile:Label runat="server" id="WelcomeMessage" />
</mobile:Form>

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值