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

RadGrid Enter key behaviour

7 Answers 507 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RvdGrint
Top achievements
Rank 1
RvdGrint asked on 31 Jan 2012, 08:36 PM
Hello,

can someone explain me the RadGrid behaviour on pressing the enter.
I've a radgrid with property AllowSubmitOnEnter is set to false. This causes strange behaviour. Sometimes the Enter Key causes an InitInsert and sometimes it causes an Edit command.
I expect the enter key always to do an update. Can someone tell me how to force this behaviour?

Regards,
  Jos Meerkerk

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Feb 2012, 11:11 AM
Hello josM,

The AllowSubmitOnEnter property is used to set whether the edit form will be submited when the ENTER key is pressed.

Thanks,
Princy.
0
RvdGrint
Top achievements
Rank 1
answered on 01 Feb 2012, 11:16 AM
Princy,

OK. But is it possible to fire a Custom command on pressing enter in a RadGrid?
In my case I want to load a custom usercontrol on pressing enter on a selected grid row.
So is it possible to catch the Enter press an fire a custom command instead of the 'Edit' or 'InitInsert' the Enter normally fires?

How do you explain that sometimes 'InitInsert' is fired and sometimes 'Edit'?

Regards,
  Jos
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Feb 2012, 11:41 AM
Hello JosM,

Try the following aspx and javascript to catch the Enter key press and to fire a custom command of yours.
aspx:
<ClientSettings>
      <ClientEvents OnKeyPress="OnKeyPress" />
</ClientSettings>
JS:
<script type="text/javascript">
function OnKeyPress(sender, args)
{
 if (args.get_keyCode() == 13)
   {
     sender.MasterTableView.fireCommand("CustomCommand","");
   }
}
</script>

Thanks,
Princy.
0
RvdGrint
Top achievements
Rank 1
answered on 01 Feb 2012, 01:44 PM
Princy,

this works fine if I want to handle the customcommand at the serverside.
I'll catch the customcommand also clientside with:
<ClientEvents OnCommand="GridLedgerCommand" OnKeyPress="GridLedgerKeyPress" />
      </ClientSettings>

function GridLedgerCommand(sender, args) {
  var _command = args.get_commandName();
  var _argument = args.get_commandArgument();
 
  if (_command == "CustomCommand") {
     ItemClick('LOADCONTROL', '~/UC/FIN/AccountInfo.ascx', 7, 193, '');
    args.set_cancel(true);
  }
}

As you can see I'm calling a function ItemClick which forces a postback:
function ItemClick(sType, sURL, iModuleID, iObjectID, sSessionParams) {
   var _event = sType + '::' + sURL + '::' + iModuleID + '::' + iObjectID + '::' + sSessionParams;
   __doPostBack('ctl00_Main', _event);
}

When debugging the aspx file the eventArgument  of the page.Request is empty. It seems the postback is overrulled somewhere.
Do you have any idea how to fix this.

Regards,
  Jos.






0
RvdGrint
Top achievements
Rank 1
answered on 01 Feb 2012, 02:11 PM
Princy,

I used this thread 
And defined a OnKeyDown event on the grid  like:
function GridLedgerKeyDown(sender, args) {
  if (args.keyCode == 13) {
    args.cancelBubble = true;
    args.returnValue = false;
 
    if (args.stopPropagation) {
      args.stopPropagation();
      args.preventDefault();
    }
 
    ItemClick('LOADCONTROL', '~/UC/FIN/AccountInfo.ascx', 7, 193, '');
  }
}

And this solved my problem.

Thnx,

Regards, 
  Jos.

0
srinivas
Top achievements
Rank 1
answered on 12 Dec 2012, 09:09 AM
Hi 

<script type="text/javascript">
function OnKeyPress(sender, args)
{
 if (args.get_keyCode() == 13)
   { args.set_cancle(true);
//     sender.MasterTableView.fireCommand("CustomCommand","");
   }
}
</script>

The Above code is working to stop the enter event. but i need to get the selected row functionality. I have a link button in my item template. any response for this please. 
0
Eyup
Telerik team
answered on 17 Dec 2012, 07:34 AM
Hi Srinivas,

I am afraid it is difficult to figure out your exact requirement by the provided info only. Could you please elaborate some more on your specific scenario and what you want to achieve? Thus, we will be able to suggest a proper approach.

All the best,
Eyup
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
RvdGrint
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
RvdGrint
Top achievements
Rank 1
srinivas
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or