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

Prevent default button behavior of "Add new record"

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg S
Top achievements
Rank 1
Greg S asked on 19 Jul 2016, 10:48 PM

If a page has no other controls except a grid with the add new record command, whenever a user presses enter they get the insert behavior - even if they're in the middle of editing a record. It's confusing and annoying if you have a grid configured for modal, popup edits - and you press enter while editing. RadGrid launches a 2nd insert popup on top of the edit popup.

How can I prevent the add new button from behaving like a default button?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 22 Jul 2016, 06:54 AM
Hi Greg,

It is general problem, not caused by the grid itself. On enter key the default button of the from will be pressed. If there is no explicitly set button, the first button is considered as default. Some browsers may behave differently.

Since in the ASP architecture all elements are in the form. Instead of normal page where you would have only the form elements inside a form, it could happen the "Add New Record" to be the first button in your form thus making it default button. You have to explicitly set Default Button for your form, and prevent the submit.

Most people use such approach:
<form runat="server" defaultbutton="button1">
<asp:Button ID="button1" runat="server" Enabled="false" style="display: none;" />
But of course it depends on your page, if you like to do something else on enter and so on.

Check this thread for some other solutions:
http://stackoverflow.com/questions/1473388/canceling-the-default-submit-button-in-asp-net

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.
Tags
Grid
Asked by
Greg S
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or