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

Disable enter when editing (multi row edit)

2 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 01 Oct 2013, 09:00 PM
Hi,

I have a grid bound to a list and I want to disable the enter key when it is pressed anywhere in the grid.

I have already followed this article and it did not work. I also tried setting the form's default button to an invisible button that doesn't do anything, but it's still not working.


This grid is always in edit mode (multi row edit).

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Oct 2013, 05:28 AM
Hi Garrett,

Have you switched on the KeyboardNavigation feature of the grid?If so you can set it to false and check if the key fires.
If the grid's keyboard navigation is turned off, perhaps the page is performing a post back on a default button which is hit on ENTER. Therefore, you need to prevent the key press event from bubbling to prevent from reaching the default button. In order to achieve this, attach an event handler to the client OnKeyPress event of the grid and define the client handler method as follows:

ASPX:
<ClientSettings AllowKeyboardNavigation="true" ClientEvents-OnKeyPress="KeyPressed">  
</ClientSettings>

JS:
<script type="text/javascript">
    function KeyPressed(sender, args) {
        if (args.get_keyCode() == 13) {
            var e = args.get_domEvent().rawEvent;
            e.returnValue = false;
            e.cancelBubble = true;
 
            if (e.stopPropagation) {
                e.preventDefault();
                e.stopPropagation();
            }
        }
    }
</script>

Thanks,
Shinu

0
Garrett
Top achievements
Rank 1
answered on 04 Oct 2013, 06:37 PM
This method works quite well, thanks!
Tags
Grid
Asked by
Garrett
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Garrett
Top achievements
Rank 1
Share this question
or