Prevent default button behavior of "Add new record"

2 posts, 0 answers
  1. Greg S
    Greg S avatar
    8 posts
    Member since:
    Jul 2015

    Posted 19 Jul 2016 Link to this post

    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?


  2. Vasil
    Vasil avatar
    1642 posts

    Posted 22 Jul 2016 Link to this post

    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:

    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.
Back to Top