Andreas N.
Top achievements
Rank 2
Andreas N.
asked on 12 Mar 2009, 12:51 PM
Hi,
I am looking for a way to cancel the ItemCreated and ItemDatabound event in case of exception.
The situation is as follows; I use these events to create a dynamic edit form from code behind when the user issues a grid EditCommand and to fill e. g. Comboboxes from data sources. In case of an exception I want to be able to intercept/undo the process of the edit form creation and revert the grid back to normal display mode.
As ItemCreated and ItemDatabound do not use e.Canceled I look for a different way of doing this.
Thank you
Nic
I am looking for a way to cancel the ItemCreated and ItemDatabound event in case of exception.
The situation is as follows; I use these events to create a dynamic edit form from code behind when the user issues a grid EditCommand and to fill e. g. Comboboxes from data sources. In case of an exception I want to be able to intercept/undo the process of the edit form creation and revert the grid back to normal display mode.
As ItemCreated and ItemDatabound do not use e.Canceled I look for a different way of doing this.
Thank you
Nic
7 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 12 Mar 2009, 01:23 PM
Hello Andreas,
You cannot cancel the ItemCreated or ItemDataBound events of a grid directly but possibly you can check if the exception is null and if so then create the edit form.
Thanks
Princy.
You cannot cancel the ItemCreated or ItemDataBound events of a grid directly but possibly you can check if the exception is null and if so then create the edit form.
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (exception == null) |
| { |
| // create edit form |
| } |
| } |
Thanks
Princy.
0
Hello Andreas,
You can handle Page OnError event and redirect to the current page.
Kind regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can handle Page OnError event and redirect to the current page.
| protected override void OnError(EventArgs e) |
| { |
| if (Server.GetLastError() is something) |
| { |
| Server.ClearError(); |
| Response.Redirect(Request.Url.ToString()); |
| } |
| base.OnError(e); |
| } |
Kind regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andreas N.
Top achievements
Rank 2
answered on 12 Mar 2009, 03:54 PM
Hi,
thanks for the answer,
but the only thing I want in case of an exception, is have the grid cancel the edit phase and revert to normal display. Without reloading the page.
To further elaborate; the edit form should not be shown in case of an exception.
Thank you
Nic
thanks for the answer,
but the only thing I want in case of an exception, is have the grid cancel the edit phase and revert to normal display. Without reloading the page.
To further elaborate; the edit form should not be shown in case of an exception.
Thank you
Nic
0
Hello Andreas,
It is not possible to cancel the page lifecycle. Even if you cancel ItemCreated event you will receive an empty page.
If your RadGrid is ajaxified you can handle the error using the MS AJAX framework capabilities. In this way you can prevent the default behavior and suppress the error.
Error Handling For Ajax Requests
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
It is not possible to cancel the page lifecycle. Even if you cancel ItemCreated event you will receive an empty page.
If your RadGrid is ajaxified you can handle the error using the MS AJAX framework capabilities. In this way you can prevent the default behavior and suppress the error.
Error Handling For Ajax Requests
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andreas N.
Top achievements
Rank 2
answered on 13 Mar 2009, 06:04 PM
Hello Daniel,
thanks for answering.
I do not want to cancel the page lifecycle.
I just want to make sure, that in case of an exception in ItemCreated/Itemdatabound, the grid reverts to displaymode instead of continuing and showing an edit form.
Thanks
Nic
thanks for answering.
I do not want to cancel the page lifecycle.
I just want to make sure, that in case of an exception in ItemCreated/Itemdatabound, the grid reverts to displaymode instead of continuing and showing an edit form.
Thanks
Nic
0
Hello Andreas,
If I understand you properly, you want to persist the previous state of the page when an error occurs on the server. Please note that when the exception is thrown, no further code will be executed and the error will propagate to the point, where it will be handled. If your are in asynchronous request and an error occurs, the server will send a response to the client which will notify the PageRequestManager about the error. If you want to prevent the default behavior you can use my previous suggestion.
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
If I understand you properly, you want to persist the previous state of the page when an error occurs on the server. Please note that when the exception is thrown, no further code will be executed and the error will propagate to the point, where it will be handled. If your are in asynchronous request and an error occurs, the server will send a response to the client which will notify the PageRequestManager about the error. If you want to prevent the default behavior you can use my previous suggestion.
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Soeren
Top achievements
Rank 1
answered on 24 Jul 2013, 01:11 PM
I know this is an old thread. But I was struggling for hours with this.
This worked for me
This worked for me
protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { GridEditFormItem oDataItem = e.Item as GridEditFormItem; //Logic etc.. // if error RadAjaxManager1.Alert("Error"); oDataItem.Edit = false; }}