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

Can't cancel add new item if there are validation errors

4 Answers 239 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 2
Mike asked on 05 Dec 2011, 07:54 PM
Hi,

I have a problem related to the RadGridView. I allow users to add a row to the grid view but want to allow them to cancel even if there are validation errors. The common situation would be for them to leave a required field blank when they click the cancel button. I don't use the RadButton (just the standard Button) and have add, save and cancel buttons. The add and cancel buttons are tied to their own click events while the save button is tied to a save command via the Command= property in the gridview. I have about 20 of these that are used to maintain database look up tables' contents.

The symptom is that a user clicks the add button which inserts a new row in the grid view and sets the focus on the first field which is required. If the user then tries to click the cancel button, the field is validated, highlighted in red and the cancel button click event never fires.

How do I get the cancel button to cancel even with invalid data?

Thanks,
Mike

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 06 Dec 2011, 12:48 PM
Hi Mike,

When the GridView loses its focus, the ActionOnLostFocus is "CommitEdit" by default. When the cell is invalid then it cannot be committed.
So if you try to move the focus, you can only if there are no errors. Otherwise the cell is still in edit mode with an error message. Do I understand right, that this is the problem that you have?

If so, you could set this ActionOnLostFocus to "CancelEdit".  That way you will be able to move the focus when the cell value is not valid.


Regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Mike
Top achievements
Rank 2
answered on 06 Dec 2011, 05:22 PM
Thanks, that works, but not quite right. Now when I click the cancel button, the gridview loses focus but I have to click the cancel button twice to remove the row that was added. How do I get the click event in the cancel button to fire the first time I click on it?

Thanks,
Mike
0
Dimitrina
Telerik team
answered on 07 Dec 2011, 04:23 PM
Hello Mike,

 Indeed you are right. We will further investigate why on cancelling the edit the focus does not move.
Meanwhile you could set the ActionOnLostFocus to be "None". That way the click event in the cancel button will be fired the first time when you click on it.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Tyree
Top achievements
Rank 2
answered on 08 Dec 2011, 03:14 AM
Is this cancel button in the row or outside the grid? If its in the row try setting IsTabStop=False on the button.
Tags
GridView
Asked by
Mike
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
Mike
Top achievements
Rank 2
Tyree
Top achievements
Rank 2
Share this question
or