Click 和Command
来源:互联网 发布:录像软件bandicam 编辑:程序博客网 时间:2024/05/22 09:05
Methods
Description
OnClick
Raises the Click event.
OnCommand
Raises the Command event.
Events
Description
Click
This event is raised when the button is clicked and the form containing the button is submitted to the server.
Command
This event also is raised when the button is clicked. However, the values of the CommandName and CommandArgument properties are passed with this event.
When a button is clicked, the form containing the button is submitted, and both Click and Command events are raised. To handle a Click event, you add a subroutine to your page as follows:
Sub Button_Click( s As Object, e As EventArgs ) End Sub
To handle a Command event, add a subroutine to your page like this:
Sub Buttom_Command( s As Object, e As CommandEventArgs ) End Sub
The only difference between a Click event and a Command event is that additional information—the values of the CommandName and CommandArgs properties—is passed to the Command event.
In Listing 2.6, for example, the btnCounter_Click subroutine is associated with the Button control's Click event. This subroutine adds one to the value of the Button control's Text property.
Listing 2.6 Button.aspx
<Script Runat="Server"> Sub btnCounter_Click( s As Object, e As EventArgs ) btnCounter.Text += 1 End Sub </Script> <html> <head><title>Button.aspx</title></head> <body> <form Runat="Server"> <asp:Button id="btnCounter" text="1" OnClick="btnCounter_Click" Runat="Server"/> </form> </body> </html>
If you need to add multiple buttons to a form, and you want to pass different information depending on which buttons are clicked, you can use the Command event instead of the Click event. For example, the page in Listing 2.7 displays different values depending on which buttons are clicked.
Listing 2.7 ButtonCommand.aspx
<Script Runat="Server"> Sub Button_Command( s As Object, e As CommandEventArgs ) Dim intAmount As Integer intAmount = e.CommandArgument If e.CommandName = "Add" Then lblCounter.Text += intAmount Else lblCounter.Text -= intAmount End If End Sub </Script> <html> <head><title>ButtonCommand.aspx</title></head> <body> <form Runat="Server"> <asp:Button Text="Add 5" CommandName="Add" CommandArgument="5" OnCommand="Button_Command" Runat="Server"/> <asp:Button Text="Subtract 10" CommandName="Subtract" CommandArgument="10" OnCommand="Button_Command" Runat="Server"/> <p> <asp:Label id="lblCounter" text="1" Runat="Server"/> </form> </body> </html>
When you click the first button in Listing 2.7, the value of the Label control named lblCounter is incremented by five. The CommandName property of the first button has the value Add, and the CommandArgument property has the value 5.
When you click the second button, the value of the Label control named lblCounter is decremented by 10. The CommandName property of the second button has the value Subtract, and the CommandArgument property has the value 10.
The values of both the CommandName and CommandArgument properties are retrieved from the CommandEventArgs parameter (the second parameter passed to the Button_Command subroutine).
You can assign anything you please to either the CommandName or CommandArgument properties. These properties accept any string value.
- Click 和Command
- The Selenium ‘click’ Command
- AttributeError: module 'click' has no attribute 'command'
- $(select).click(function(){})和$(select).click(addComt())
- click 和 touch 区别
- click和onclick
- Click和Velocity浅析。
- javascript中onclick和click
- tap 和click 事件区别
- tap 和click 事件区别
- 解决flex click 和 double click的问题
- mousedown和onmousedown,click和onclick区别
- android click 和onTouch 事件处理机制
- [Apache Click快速开发]Panel和Tree
- Android:Touch和Click的区别 编辑
- NS3安装问题(click和openflow)
- android click 和onTouch 事件处理机制
- android click 和onTouch 事件处理机制
- SILVERLIGHT开始在整个网站积累更深入的体验(转载)
- ASP.Net新手项目经验谈
- 利用JavaScript实现简单的拖动层(只使用于IE)
- ASP.NET AJAX官方资源大量更新
- 用T_sql建表,删除表,判断表
- Click 和Command
- 计算机系的男生之所以是光棍的原因(转)
- 乐?哀?
- SSH网上商城【什么是SSH】
- 计算在线人数
- ASP.NET 2.0构建动态导航的Web应用程序(TreeView和Menu ) (海东的技术资料)
- POJ2531-Network Saboteur-暴力枚举+记忆化/dfs/随机化乱搞
- 接口略解
- 构造,析构,覆盖,重载,隐藏