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

Inconsistent behavior with a onkeypress action from an edit template

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 05 Dec 2012, 07:55 PM
What I want to do is simply close the popup with the Esc key.  

I have a RadGrid set up with popup edit form template.    The popup itself contains two RadButtons, a RadEditor, two RadDateTime Pickers, and a RadTextBox.

In the ClientSettings I have the declartion OnKeyPress="OnKeyPress".

The Javascript function is as follows:
  function OnKeyPress(sender, args) {
            var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();           
            if (args.get_keyCode() == 27) {
                masterTable.fireCommand("CancelAll", "");
            }
        }

This works, sort of.

It does not work on the initial appearance of the popup or if the RadEditor has the focus.  If I set the focus to one of the other controls or just click on the body of the popup, it works fine.

Suggestions?

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 10 Dec 2012, 02:51 PM
Hi Boris,

In order to close the popup form after the initial appearance you have to focus one of the controls inside. This can be achieved by intercepting the OnItemDataBound event of the RadGrid and setting the focus on one of the controls. A sample demonstration of this approach is shown here. Intercepting the key press in the Editor is a different matter. Using the OnClientLoad you will have to attach an event handler that will notify you when esc button is pressed. Attaching an event handler for the RadEditor is explained in this help topic.

Kind regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or