当按下回车键时调用特定按钮的 onClick 事件 C#
我试图在特定的 asp:textbox 控件中按 Enter 键时触发特定的 asp:button onclick 事件。
另一个需要考虑的因素是该按钮位于 asp:Login 控件模板内。
我不知道该怎么做,请在明信片上提出建议。
I'm trying to get a specific asp:button onclick event to fire when I press the enter key in a specific asp:textbox control.
The other factor to be taken into account is that the button is within a asp:Login control template.
I've no idea how to do this, suggestions on a postcard please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以查看
DefaultButton
面板控件的属性。You could look at the
DefaultButton
property of the panel control.您可以在窗体上设置 DefaultButton 属性。 作为标记中表单标签的属性 DefaultButton = "btnSubmit" 或在代码隐藏中使用类似的内容:
You could set the DefaultButton property on the form. Either as an attribute of the form tag in your markup DefaultButton = "btnSubmit" or using something like this in your code-behind:
它的 HtmlForm。默认按钮
Its HtmlForm.DefaultButton
你需要用 javascript 来完成。 使用 jQuery 非常简单。
你可以做类似的事情(我的想法,未经测试):
编辑:请注意,虽然 jQuery 在跨浏览器上工作得非常出色,但此处描述了按键的一些怪癖。
哎呀,我没有看到你说“输入键”,我以为你说的是“任意键”,是的,在这种情况下,请在 asp:panel 上使用 DefaultButton
You need to do it with javascript. It's really easy with jQuery.
You can do something like (off the top of my head, not tested):
Edit: Be aware that although jQuery works exceptionally cross browser, there are some quirks with keypress described here.
Whoops i didnt see you said the "enter key" i thought you said "any key", yeah in that case use DefaultButton on asp:panel