Telerik UI for ASP.NET AJAX

Sometimes it may be necessary, when keyboard navigation for the control has been enabled, to disable/cancel certain key press. For example, one may not want to enter edit mode (when pressing [Enter]) or to allow only one-way movement with the keys.

The necessary steps to achieve this are listed below:

  1. Enable Keyboard navigation

  2. Specify a function that will be called client-side, when a key is pressed

  3. In the client-side function, check the code of the key that was pressed

  4. Depending on a condition, cancel the key press

This approach is demonstrated in the code samples below:

CopyASPX
<ClientSettings AllowKeyboardNavigation="true" ClientEvents-OnKeyPress="KeyPressed">
     <Selecting AllowRowSelect="true" />
</ClientSettings>

And the JavaScript code:

CopyJavaScript
function KeyPressed(sender, eventArgs) {
  if (eventArgs.get_keyCode() == 13) {
    eventArgs.set_cancel(true)
  }
}