处理两个TextBox的提交动作

发布于 2024-09-29 23:40:09 字数 566 浏览 0 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(2

咋地 2024-10-06 23:40:09

看看这个: 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.

笑叹一世浮沉 2024-10-06 23:40:09

答案与我的预期有点不同,但在哲学上就像 @jamietre 强化的我最初的想法。

我必须用带有 DefaultButton 属性的 标记包围控件。 A-like-a 所以:

<asp:Panel ID="ButtonPanel" runat="server" DefaultButton="btnSubmit">
                        <asp:Label ID="Label1" runat="server" Text="Course:"></asp:Label>
                        <asp:TextBox ID="txtPrereqSearch" runat="server"
                            ontextchanged="txtPrereqSearch_TextChanged"></asp:TextBox>
                            <asp:TextBoxWatermarkExtender ID="txtPrereq_TextBoxWatermarkExtender" 
                    runat="server" Enabled="True" TargetControlID="txtPrereqSearch" 
                    WatermarkCssClass="Watermark" WatermarkText="e.g., MATH201"></asp:TextBoxWatermarkExtender>
                        <asp:Button ID="btnSubmit" CssClass="InvisibleSubmit" runat="server" Text="Submit" OnClick="txtPrereqSearch_TextChanged"/>
                    </asp:Panel>

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 a DefaultButton attribute. A-like-a so:

<asp:Panel ID="ButtonPanel" runat="server" DefaultButton="btnSubmit">
                        <asp:Label ID="Label1" runat="server" Text="Course:"></asp:Label>
                        <asp:TextBox ID="txtPrereqSearch" runat="server"
                            ontextchanged="txtPrereqSearch_TextChanged"></asp:TextBox>
                            <asp:TextBoxWatermarkExtender ID="txtPrereq_TextBoxWatermarkExtender" 
                    runat="server" Enabled="True" TargetControlID="txtPrereqSearch" 
                    WatermarkCssClass="Watermark" WatermarkText="e.g., MATH201"></asp:TextBoxWatermarkExtender>
                        <asp:Button ID="btnSubmit" CssClass="InvisibleSubmit" runat="server" Text="Submit" OnClick="txtPrereqSearch_TextChanged"/>
                    </asp:Panel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文