views:

26

answers:

2

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!

A: 

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
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 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>
clifgriffin
I think it would work even without using DefaultButton (not that there's any harm in using it) since the only button would become the default anyway.
jamietre