这是在文本框中提交输入按钮的好解决方法吗?

发布于 2024-12-21 01:26:46 字数 266 浏览 3 评论 0原文

所以我有一个页面,它有多个文本框、链接按钮和按钮。目前,用户单击链接按钮“编辑”,这允许他们通过文本框在该行中输入数据。然而,按下 Enter 键后,其中一个按钮的事件就会被触发……这根本不是所希望的。显然,这是内置的默认行为?

是否可以关联每个文本框,以便按 Enter 键将作用于指定的特定链接按钮或按钮,而不需要文本框处于单独的表单中?

如果这是不可能的,我将尝试创建一个按钮并将其设为默认表单按钮,但禁用并隐藏它,以便按 Enter 键不会提交任何内容。

谢谢!

So I have a page, it had multiple textboxes, linkbuttons, and buttons. Currently, a user clicks a linkbutton "Edit" which allows them to enter data in that row, via textboxes. However, upon pressing enter, the event for one of the buttons fired...this is not desired at all. Apparently, this is the default behavior built in?

Is it possible to associate each textbox so that pressing enter will act on a specific assigned linkbutton or button, without the textboxes being in separate forms?

If this is not possible, I'm going to try and create a button and make it the default form button, but disable and hide it, so that pressing enter submits nothing.

Thanks!

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

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

发布评论

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

评论(3

删除会话 2024-12-28 01:26:46

您可以将 Button 控件上的 UseSubmitBehavior 属性设置为“false”。这将导致按钮呈现为 标记,而不是 标签。因此,按下 Enter 键不会导致按钮被按下,除非按钮实际上具有焦点。

<asp:Button runat="server" UseSubmitBehavior="false" ... />

You can set the UseSubmitBehavior property to "false" on a Button control. This will cause the button to be rendered as an <input type="button" /> tag instead of an <input type="submit" /> tag. As a result, pressing the Enter key will not cause the button to be pressed, unless the button actually has the focus.

<asp:Button runat="server" UseSubmitBehavior="false" ... />
苏大泽ㄣ 2024-12-28 01:26:46

您可以重写每个文本框的 KeyPress 事件来捕获回车键,然后触发相应按钮的代码。

if(e.KeyChar == '\n') 
   // execute button code

You can override the KeyPress event for each textbox to catch the enter key and then fire the code for the corresponding button.

if(e.KeyChar == '\n') 
   // execute button code
挽梦忆笙歌 2024-12-28 01:26:46

您可以将它们放在单独的面板中,并使用 defaultbutton 属性告诉面板在按下 Enter 时使用哪个按钮。

you can put them in separate panels and use the defaultbutton attribute to tell the panel which button to use when enter is pressed.

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