Button.click事件和button.command事件有什么区别?
Whats the difference between Button.Click Event and Button.Command Event in asp.net?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Whats the difference between Button.Click Event and Button.Command Event in asp.net?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
正如文档所暗示的,Button.Command 事件允许您指定一个“命令”,以便您可以区分单击了哪个按钮等。
As the documentation implies,the Button.Command event allows you to specify a "command" so that you can differentiate between which button was clicked,etc.
按钮单击和命令的行为方式相同。两者都会执行 PostBack 操作,差别很小。
如果按钮同时关联了 Click 和 Command 事件,则先执行 Click eventHandler,然后执行 commandHandler。
Click 事件不会发送任何参数,而 Command 会将 CommandName 和 CommandAgument 等参数发送到 codeBehind 代码。因此,这可以帮助开发人员在有多个按钮时找到触发哪个按钮。
Button Click and Command behaves with the same way. Both will perform PostBack operation and has small difference.
If a button has both Click and Command events associated with it, then Click eventHandler is performed first, then commandHandler is performed.
Click event does not send any parameters whereas Command will send parameters like CommandName and CommandAgrument to codeBehind code. So, this helps developers to find which button is triggered when they have multiple buttons.