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

5 posts, 0 answers
  1. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 05 Dec 2011 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Dec 2011 Link to this post

    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 >>
  3. DevCraft banner
  4. Mike
    Mike avatar
    32 posts
    Member since:
    May 2011

    Posted 06 Dec 2011 Link to this post

    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
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Dec 2011 Link to this post

    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 >>

  6. Tyree
    Tyree avatar
    105 posts
    Member since:
    Dec 2006

    Posted 07 Dec 2011 Link to this post

    Is this cancel button in the row or outside the grid? If its in the row try setting IsTabStop=False on the button.
Back to Top
DevCraft banner