Hello.
I have this issue: I have grid. When I try to add new record by EditForm I need to catch keydown. If Enter was pressed - save record, if Esc - Cancel.
All that relates to saving is OK: I call fireCommand("PreformInsert", "") from javascript, in code behind grd_ItemCommand function gets command.
But when I press Esc grd_ItemCommand doesn't get command (but postback fires).
Could you help me by any advice?
I have this issue: I have grid. When I try to add new record by EditForm I need to catch keydown. If Enter was pressed - save record, if Esc - Cancel.
if
(e.keyCode == 13) {
var
masterTable = $find(
"<%= grd.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"PerformInsert"
,
""
);
}
if
(e.keyCode == 27) {
var
masterTable = $find(
"<%= grd.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"Cancel"
,
""
);
}
All that relates to saving is OK: I call fireCommand("PreformInsert", "") from javascript, in code behind grd_ItemCommand function gets command.
But when I press Esc grd_ItemCommand doesn't get command (but postback fires).
Could you help me by any advice?
6 Answers, 1 is accepted
0

Sergey
Top achievements
Rank 1
answered on 27 Feb 2015, 03:42 PM
I added a record into data source, so it became not empty and then OnItemCommand gets command on Esc press. But EditForm doesn't hide on it.
I've added in EditFormTemplate a button with CommandName="Cancel" for test and when I press it EditForm hides independently of records existence in data source.
I've added in EditFormTemplate a button with CommandName="Cancel" for test and when I press it EditForm hides independently of records existence in data source.
0
Hello Sergey,
To achieve the desired functionality you need to use “CancelAll” command:
Or “CancelUpdate” command with passed row index:
Please give one of the suggestions try and let me know if it helps.
Regards,
Radoslav
Telerik
To achieve the desired functionality you need to use “CancelAll” command:
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"CancelAll"
, “”);
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"CancelUpdate"
, IndexOfTheEditedRow);
Please give one of the suggestions try and let me know if it helps.
Regards,
Radoslav
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Sergey
Top achievements
Rank 1
answered on 05 Mar 2015, 08:46 AM
I tried to use "CancelAll" command, but it didn't help.
0
Hi Sergey,
I am sending you a simple example which demonstrates that with “CancelAll” command the edit form is closed. Please check it out and let me know what differs in your side.
Looking forward for your reply.
Regards,
Radoslav
Telerik
I am sending you a simple example which demonstrates that with “CancelAll” command the edit form is closed. Please check it out and let me know what differs in your side.
Looking forward for your reply.
Regards,
Radoslav
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Sergey
Top achievements
Rank 1
answered on 16 Mar 2015, 03:11 PM
Please, excuse my long silence.
So, about differs: OnItemDataBound I do next:
In javascript function tabKeypress I use conditions from my first post. And when I press Escape button EditForm doesn't hide.
I've got round this for now by creating a hidden button and pressing it by javascript function (method Click();).
So, about differs: OnItemDataBound I do next:
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem dataItem = (GridEditFormInsertItem)e.Item;
var txtBx = (TextBox)dataItem.FindControl(
"tbTextBox"
);
var txtBxNextNumeric = (RadNumericTextBox)dataItem.FindControl(
"tbNumericTextBox"
);
if
(txtBx !=
null
)
txtBx.Attributes.Add(
"onKeyDown"
,
"return tabKeypress(event,'"
+ txtBxNextNumeric.ClientID +
"');"
);
}
In javascript function tabKeypress I use conditions from my first post. And when I press Escape button EditForm doesn't hide.
I've got round this for now by creating a hidden button and pressing it by javascript function (method Click();).
0
Hi Sergey,
Can you please confirm that the code which call fireCommand is reached when you press Escape button? Also it will be helpful if you could post the aspx page markup with the related code behind. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.
Regards,
Radoslav
Telerik
Can you please confirm that the code which call fireCommand is reached when you press Escape button? Also it will be helpful if you could post the aspx page markup with the related code behind. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.
Regards,
Radoslav
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.