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

focus changing from a radgrid to another

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Louis-Philippe
Top achievements
Rank 1
Louis-Philippe asked on 09 Mar 2011, 11:17 PM
Hello,
Here's a funny one! I have two RadGrid in the same page, one above the other. The one on the bottom support edit/update mode using a WebUserControl. When in edit mode, if the focus is in a control witch doesn't handle the enter key, let say a RadNumericTextBox, if the user hit the enter key, the focus jump from the WebUserControl of the radGrid in the bottom, to the first ImageButton, of the first row, of the radGrid above. Very annoying! I tried to block the enter key using clientevents-onkeypress event when in edit mode, but the event still reach the radGrid above. I'm able to block the execution of the event associated with the ImageButton, but I can't find a way to block the change of focus. Any idea on how to prevent this behavior or at least use client-side scripting to bring the focus back to the previously selected control? I can't tell the user to avoid the enter key...

Thank you for your time,
Louis-Philippe

1 Answer, 1 is accepted

Sort by
0
Louis-Philippe
Top achievements
Rank 1
answered on 10 Mar 2011, 09:50 PM
Hello,
If anyone got such ridiculous behavior, here's how to fix it. Every control in your WebUserControl that produce weird change in focus must implement client-side OnKeyPress event like this:
<ClientEvents OnKeyPress="KeyPressed" />
The definition of KeyPressed must be inside of the file holding the grid, not in the WebUserControl file. As seen in this page http://www.telerik.com/help/aspnet-ajax/grdcancelenterarrowkeypress.html
you can block the enter key this way:

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

For my setup, I had to handle OnKeyPress event in the DateInput section of RadDateTimePicker
<DateInput TabIndex="80" DisplayDateFormat="yyyy-MM-dd HH:mm" DateFormat="yyyy-MM-dd HH:mm"
                                  SelectionOnFocus="SelectAll">
       <ClientEvents OnKeyPress="KeyPressed" />
</DateInput>
and also for RadNumericTextBox. I'm pretty sure that other control may behave the same way.

I first tried to block the enter key for the whole radgrid when in edit/insert mode. It did block the enter key in that grid, but didn't prevent the focus from changing grid.

I still can explain why it happen, but at least it can be fixed... Hope this help someone.

Louis-Philippe
Tags
Grid
Asked by
Louis-Philippe
Top achievements
Rank 1
Answers by
Louis-Philippe
Top achievements
Rank 1
Share this question
or