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

Force close editform

1 Answer 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iris
Top achievements
Rank 1
Iris asked on 08 Aug 2012, 07:29 AM
I'm using editForm template and I have a Cancel button on my edit form. This cancel button has CancelCommand name. All is well if I click the Cancel button in normal condition and it closes the edit form as expected. However, if I have validation errors on the editForm, clicking the Cancel button does not close the editForm and I suspect that it causes validation to be fired.

Can anyone tell me how to close the editForm regardless whether I have validation errors on the form or not?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Aug 2012, 09:56 AM
Hi,

In order to close the edit form, you can access the Cancel button in ItemDataBound event and set CausesValidation as false. Here is the sample code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
  {
    GridEditFormItem item = (GridEditFormItem)e.Item;
    Button btn = (Button)item.FindControl("cancelbtn");
     btn.CausesValidation = false;
  }
}

Thanks,
Princy.
Tags
Grid
Asked by
Iris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or