This is a migrated thread and some comments may be shown as answers.

SingleClick Button and 'Enter' on Search form

6 Answers 319 Views
Button
This is a migrated thread and some comments may be shown as answers.
Eli
Top achievements
Rank 1
Veteran
Eli asked on 16 Mar 2016, 06:19 PM
I have a search form with many fields set up and working fine.  When I set the "Search" RadButton to SingleClick=True, it will no longer submit the form when pressing ENTER in the various input search boxes.  It appears the page does a postback but the button click event is never fired.  The button works as expected when clicking, but often users will use tab and enter text and then press enter on the form rather than clicking the button.  Suggestions?

6 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 17 Mar 2016, 12:53 PM
Hi Eli,

Try to set defaultbutton="YourButtonId" in the form declaration.

https://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton%28v=vs.110%29.aspx

Regards,
Vasil
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Eli
Top achievements
Rank 1
Veteran
answered on 17 Mar 2016, 01:22 PM

The Form tag is on a Masterpage so I did not think to do it this way, but it appears to work well.  Thank you.

 

Dim mp As MasterPage = Me.Page.Master
Dim form As HtmlForm = CType(mp.FindControl("Form1"), HtmlForm)
form.DefaultButton = Me.rbSearch.UniqueID
0
Julien
Top achievements
Rank 1
answered on 07 Jul 2016, 02:52 PM
It does not fix the problem, it only hides it.
0
Vasil
Telerik team
answered on 07 Jul 2016, 03:17 PM
Hello Julien,

Yes, if we consider that HTML specification by design to have a problem.

Anyway the issue is not in our controls by any means. Most of the people just place hidden button on their pages and make it default button, to prevent unwanted submit by the form itself.

You can check for example this thread:
http://stackoverflow.com/questions/15510680/submit-on-enter-multiple-inputs
If you have 2 inputs in the page, pressing enter will submit the form even if there is no button
If you have 1 or 3 inputs in the page, pressing enter will do nothing.

It is called Implicit submission:
https://www.w3.org/TR/html5/forms.html#implicit-submission

So in case the button is not real <button> but <input>, and you have 1 more input. When you press enter, the form will submit, but the target will not be your "button". The target will be empty. In this case the framework can not know what control caused the postback, so the handler is not executes.

We can call it hiding or resolving the problem, but in both cases, the behavior is expected and solution is in general proven.

Regards,
Vasil
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Roger
Top achievements
Rank 1
Veteran
answered on 02 Aug 2018, 10:18 AM

There is a much easier approach as explained in this Stackoverflow post.

<asp:Panel ID="p" runat="server" DefaultButton="myButton">

 

If you push ENTER on a focused control which is in corresponding panel, then specified button will be the default button on submit.

Best regards,

Roger

0
Rumen
Telerik team
answered on 02 Aug 2018, 03:22 PM
Hi Roger,

Thank you for sharing yet another solution on the matter.

Best regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Button
Asked by
Eli
Top achievements
Rank 1
Veteran
Answers by
Vasil
Telerik team
Eli
Top achievements
Rank 1
Veteran
Julien
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Veteran
Rumen
Telerik team
Share this question
or