ASP.NET 表单中的 DefaultButton

发布于 2024-07-05 19:17:44 字数 65 浏览 5 评论 0原文

ASP.NET 2.0-3.5 表单的 defaultButton 和“按下 Enter 键”的最佳解决方案是什么?

What is the best solution of defaultButton and "Enter key pressed" for ASP.NET 2.0-3.5 forms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

向地狱狂奔 2024-07-12 19:17:44

由于按 Enter 键进行表单提交是 HTML 生活的一部分,因此您必须使用 javascript 捕获 Enter 键,并且只允许它在有效时通过(例如在文本区域内)。 查看< a href="http://brennan.offwhite.net/blog/2004/08/04/the-single-form-problem-with-aspnet/" rel="nofollow noreferrer">http://brennan.offwhite。 net/blog/2004/08/04/the-single-form-problem-with-aspnet/ 以获得很好的解释。

Since form submission on hitting the enter key is a part of life with HTML, you'll have to trap the Enter key using javascript and only allow it to go through when it's valid (such as within textareas). Check out http://brennan.offwhite.net/blog/2004/08/04/the-single-form-problem-with-aspnet/ for a good explanation.

街角迷惘 2024-07-12 19:17:44

只需将“defaultbutton”属性添加到表单中,并将其设置为您想要作为默认按钮的 ID。

<form defaultbutton="button1" runat="server">
    <asp:textbox id="textbox1" runat="server"/>
    <asp:button id="button1" text="Button1" runat="server"/>
</form> 

注意:这仅适用于 ASP.NET 2.0+

Just add the "defaultbutton" attribute to the form and set it to the ID of the button you want to be the default.

<form defaultbutton="button1" runat="server">
    <asp:textbox id="textbox1" runat="server"/>
    <asp:button id="button1" text="Button1" runat="server"/>
</form> 

NOTE: This only works in ASP.NET 2.0+

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