5

I have an asp.net panel with a default button setting but the button is never trigger when hitting the ENTER button. I searched SO for this question, but could not find any response that works.

How can I get btnRegister to click when the users hits ENTER ?

<asp:Panel runat="server" ID="pnlCustomer" DefaultButton="btnRegister">
    <table width="500px" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td align="right">
            <asp:Button ID="btnBackToProfile" Text="Back To Profile" runat="server" Enabled="false"
                onclick="btnBackToProfile_Click" />
        </td>
        <td align="right">
            <asp:Button ID="btnClearnForm" Text="Clear Form" runat="server" 
                OnClientClick="ClearForm1()" />
        </td>
        <td align="right">
            <asp:Button id="btnRegister" runat="server" onclientclick="document.getElementById('AlertTime').value = GetSeconds();" Text="Continue" OnClick="btnRegister_Click" />
        </td>
    </tr>
    </table>
</asp:Panel>
DNR
  • 3,706
  • 14
  • 56
  • 91
  • See this answer http://stackoverflow.com/questions/2155048/onclientclick-and-onclick-is-not-working-at-the-same-time – Tim Cadieux Aug 12 '12 at 15:53

2 Answers2

6

The first thing that I like to point here is that the default button is the control that is pressed when the focus is on one of the controls that exist inside this Panel, and not the rest of the page.

The main reason for your issue is because inside this Panel you do not have anything (else than buttons) that can keep the focus of the keyboard and send the enter to the default button.

Something like a text editor, for example: if you place a text editor inside the panel, click on it and then press enter, the default button will be fired.

So when the focus is inside this panel is on a button, and when you press enter the selected button is pressed, not the default one.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • 3
    Eh, I have a in a Panel and it's not working for me, either. Worked on our Test environment, but not Prod. There aren't any of the WebResource.axd or ScriptResource.axd files failing to load, either. :( – haliphax Sep 02 '16 at 16:01
  • @haliphax ditto. Only doesn't work in production, but works locally. Ever figure this out? – Jarrette Jan 10 '17 at 15:47
  • 1
    @Jarrette Plugins and browser can affect the way they work. Also if you have javascript errors can not work. – Aristos Jan 10 '17 at 16:09
2

I had this same issue and discovered that the Panel can't be outside of the table containing the default button. If you put your Panel inside the cell that has the button it should work.

SteveEx
  • 33
  • 5