当按下回车键时调用特定按钮的 onClick 事件 C#

发布于 2024-07-08 15:25:40 字数 143 浏览 4 评论 0原文

我试图在特定的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寄与心 2024-07-15 15:25:40

您可以查看 DefaultButton 面板控件的属性。

You could look at the DefaultButton property of the panel control.

随风而去 2024-07-15 15:25:40

您可以在窗体上设置 DefaultButton 属性。 作为标记中表单标签的属性 DefaultButton = "btnSubmit" 或在代码隐藏中使用类似的内容:

Page.Form.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:

Page.Form.DefaultButton = "btnSubmit"
旧人九事 2024-07-15 15:25:40

你需要用 javascript 来完成。 使用 jQuery 非常简单。

你可以做类似的事情(我的想法,未经测试):

$('#myTextBox').keypress(function(e){
    if(e.which == 13)
        $('#myBtn').click();
});

编辑:请注意,虽然 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):

$('#myTextBox').keypress(function(e){
    if(e.which == 13)
        $('#myBtn').click();
});

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文