0

I have 2 pages.

  1. Login page
  2. Search page (after login)

On my search page, I have several input box (text, radio, checkbox ...) . The problem is, when the cursor is at one of the input fields, and the user presses Enter, the browser send the user back to the login page.

I fixed this issue using JQuery to capture keypress event on input items. However I still don't understand why is this happening?

P/s : if you need to see my HTML code please comment. The code stays on my work computer with restricted access so I can't post it here, but I will type it here if necessary.

EagerToLearn
  • 675
  • 7
  • 24

1 Answers1

1

Place your input inside a panel and set the default button to your default control.

<asp:Panel runat="server" ID="pnlForDefault" DefaultButton="btnSearch">
 <!-- your input -->
</asp:Panel>

Now why is going back - and why I show you this panel method.
1. Maybe because you all ready have this panel on your page with wrong default button.
2. The user can press enter either when its on a text box, but also at any time, but only when the focus is inside a text box can be actually redirect that enter to some control. So either you may have some other library that take action on enter, either you press enter when you are focus on go back button....

You can also read
Default button not working in asp.net panel

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Thanks for the reply, I will check my code again. Btw I don't have a go back button on my page. Just a submit search button only. – EagerToLearn Jun 18 '18 at 09:13
  • @EagerToLearn Check if you have any other javascript library that make this go back. – Aristos Jun 18 '18 at 11:20
  • Hello @Aristos, I'm very sorry, there was a Logout button on my page, after debugging, I found out that whenever Enter key was hit, the button got submitted. But I don't want to add a DefaultButton, because when entering in textbox maybe just a habit, the User doesn't mean to search unless they were focusing on the button. By the way, could you explain to me why the Logout button got fired please? Thanks very much! – EagerToLearn Jun 20 '18 at 01:14
  • @EagerToLearn Because was first in the list of buttons... or maybe because have the default focus. – Aristos Jun 20 '18 at 06:20
  • Thanks for the reply. Yes it's the first button. But I still don't understand why entering in a textbox will lead to a button got submitted? Is there any official document about this? – EagerToLearn Jun 21 '18 at 06:26
  • @EagerToLearn on a line text editor (that not accept enters) yes in a user interface the Enter is hit the default button, the Esc hits the cancel/close if exist in a dialog - similar is on web page. – Aristos Jun 21 '18 at 06:29
  • @EagerToLearn https://msdn.microsoft.com/en-us/library/windows/desktop/dn742402%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 – Aristos Jun 21 '18 at 06:30
  • @EagerToLearn https://msdn.microsoft.com/en-us/library/windows/desktop/dn742499(v=vs.85).aspx – Aristos Jun 21 '18 at 06:31