处理两个TextBox的提交动作
我有一个 ASP.net 页面。
它有一个 Ajax Toolkit 选项卡控件。
有选项卡。
其中有我编写的自定义 ascx 控件。
我有一个执行搜索操作的文本框。它是这样声明的:
<asp:TextBox ID="txtPrereqSearch" runat="server"
ontextchanged="txtPrereqSearch_TextChanged"></asp:TextBox>
没有什么花哨的。这种格式已经运行了几个月。没有提交按钮。当我按回车键时它就会发回来。当我使用相同类型的功能添加第二个自定义控件时,出现了问题。现在,当我在这两个文本框中键入内容并按 Enter 键时,浏览器不会回发。
浏览器似乎有一种以一种形式处理一个文本框的默认方式,但当数量达到两个时,这种行为会发生变化。
有一个简单的方法可以解决这个问题吗?我想我可以创建一个隐藏的提交按钮,但当功能位于两个单独的自定义控件中时,似乎可能有更好的方法来处理这个问题。
感谢您的反馈!
I have an ASP.net page.
That has an Ajax Toolkit Tab Control.
That has tabs.
That have custom ascx controls I wrote.
I have a text box that perform a search action. It is declared like this:
<asp:TextBox ID="txtPrereqSearch" runat="server"
ontextchanged="txtPrereqSearch_TextChanged"></asp:TextBox>
Nothing fancy. This format has been working for months. There's no submit button. It just posts back when I hit enter. The problem appeared when I added a second custom control using the same type of feature. Now browsers don't postback when I type something in either of these textboxes and press enter.
It seems that browsers have a default way of handling one textbox in one form, but that behavior changes when the number reaches two.
Is there an easy way around this? I guess I can create a hidden submit button but it seems like there is probably a better way to deal with this when the functionality is in two separate custom controls.
Your feedback is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个: http://www.allasp.net/enterkey.aspx
默认行为没有提交按钮似乎取决于浏览器,并且行为确实可以取决于输入控件的数量。
我会添加隐藏的“提交”按钮(例如
style="display:none;"
),这应该确保它始终被提交。Check this out: http://www.allasp.net/enterkey.aspx
The default behavior with no submit button seems to depend on the browser, and the behavior can indeed depend on the number of input controls.
I would add hidden "submit" button (e.g.
style="display:none;"
) which should ensure that it always gets submitted.答案与我的预期有点不同,但在哲学上就像 @jamietre 强化的我最初的想法。
我必须用带有
DefaultButton
属性的
标记包围控件。 A-like-a 所以:The answer was a little different than I expected, but philosophically like my original idea that @jamietre reinforced.
I had to surround the controls with an
<asp:Panel>
tag with aDefaultButton
attribute. A-like-a so: