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

Enter key causes delete event to fire

6 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 1
Nate asked on 22 Feb 2010, 08:32 PM
Basically I have a rad grid, and the enter key is causing the delete confirm to popup.
Is there a way to cancel the delete before the confirm pops up?

Thanks,

Nate

6 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Feb 2010, 05:52 AM
Hi Nate,

One suggestion would be showing confirm in OnCommand client event of radgrid instead of setting the ConfirmText for the column. You can chek for any condition and cancel the Delete command before showing the confirm window.

aspx:
 
<telerik:GridButtonColumn UniqueName="DeleteButtonColumn" text="Delete" CommandName="Delete"
</telerik:GridButtonColumn> 

javacript:
 
    function OnCommand(sender, args) { 
        if (args.get_commandName() == "Delete") { 
            if (condition) {   // Check for condition to cancel the event, before showing confirm 
                args.set_cancel(true); // Cancel the event 
            } 
            if (!confirm('Do you really want to delete the record?')) { // Showing confirm 
                args.set_cancel(true); // Cancel the event 
            } 
        } 
    } 
Feel free to share the comments.

Think differently :)
Shinu.
0
Nate
Top achievements
Rank 1
answered on 23 Feb 2010, 03:07 PM
Cool, thanks, I ended up figuring out some javascript as well, but I like your solution better, thanks!
Nate
0
Tim
Top achievements
Rank 1
answered on 10 Oct 2013, 12:11 AM
Hi, I'm trying to get the solution posted by Shinu to work, but I can't seem to get the keyCode for the enter key. I've tried event.keyCode but that is always 0.

Thanks, all help is appreciated.
0
Angel Petrov
Telerik team
answered on 14 Oct 2013, 11:26 AM
Hello Tim,

The suggestion that Shinu had provided relies on the fact that a delete command is fired. Is that the case in your scenario? Could you please clarify what is the idea behind the accessing of the keyCode? This might not be needed as the delete command can be fired from both a button click or pressing the enter key. Do you want to cancel the deleting of an item only when an enter key is pressed? Please elaborate more on the exact scenario so we could provide a more precise suggestion.

Regards,
Angel Petrov
Telerik
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 the blog feed now.
0
Fred
Top achievements
Rank 1
answered on 16 Oct 2019, 12:54 PM

Dear Angel Petrov - I am a total noob helping to solve a weird little issue with the implementation of this Telerik control. It seems that the control is 'attached' (is this the right word?) to a field which gathers data - in this case, month and year. Our end user uses the control to enter a date and when pressing Enter, instead of the date being recorded, we receive the notice that the record is about to be deleted. ???

I'm under the impression that the control has to fire a delete command? Is this corrrect? Or can the control be assigned another command - such as "not delete" or "Save date in client file xyz on server abc", etc?

Any advice appreciated - be gentle. I'm a dullard at this stuff and am wrapping my head around it.

0
Attila Antal
Telerik team
answered on 21 Oct 2019, 08:15 AM

Hi Fred,

Generally this behavior appears when the keyboardboard navigation is enabled both for RadGrid and the controls in it. When the end user uses the keyboard keys to navigate and manage data, both RadGrid and the controls in it will listen to the keyboard events and the first catching the key takes the action.

This behavior is described in the Keyboard support

"If controls inside the grid use the same keys and combinations as the grid, and do not prevent (consume) the keydown event, you may get unexpected behavior. For example, rows may be changed in the batch edit mode while the user is attempting to navigate through a combo box list.

To prevent this, you can set the ClientSettings.AllowKeyboardNavigation property of the grid to false. Alternatively, use widgets and code that prevents the keyboard event propagation. For example, replace RadComboBox with RadDropDownList, which prevents the up and down arrows from propagating.

Whether a control should prevent the propagation of the keyboard events is a gray area and some controls may do that, while others do not. This is highly specific to each control and to each key."

This behavior could also be the result of having the delete button configured to listen for the Enter key. Whenever it's pressed, click the button. 

 

Nevertheless, I've been playing around with different scenarios and I am unable to replicate the issue.

Here is what I have tried and it does not fire the delete command when the Enter key is pressed:

 

Grid Markup

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource">
    <ClientSettings AllowKeyboardNavigation="true">
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="true" DataKeyNames="OrderID">
        <Columns>
            <telerik:GridTemplateColumn HeaderText="Template Column">
                <ItemTemplate>
                    <%# Eval("OrderDate") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" EnableKeyboardNavigation="true"></telerik:RadDatePicker>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridButtonColumn CommandName="Delete"></telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 

C# - Code Behind

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = Enumerable.Range(1, 5).Select(x => new
    {
        OrderID = x,
        OrderDate = DateTime.Now.AddDays(x),
        Freight = x * .1,
        ShipName = "Name " + x,
        ShipCountry = "Country " + x
    });
}

 

It would be very helpful if you could share some more details on the current scenario, I will take a look and see what can be done to prevent that from happening.

 

See also:

 

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Nate
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Nate
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Angel Petrov
Telerik team
Fred
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or