I may be wrong in how to manually save data here, as I'm learning how to work with a Batch grid. If so, please correct me...
I have a RadGrid in Batch mode. When the user has made all changes to the header textboxes at the top of the form, and the detail values in the RadGrid below them, the user needs to click a general Save button to save all the data to the DB. (I'm hiding the "Save changes" button in the grid.)
As I understand it, that does nothing to the underlying data. Instead, it calls the server-side grdPODetails_BatchEditCommand, at which point I manually update the data. In there, I'm updating the dataset that was initially loaded onto the page behind the scenes...
As you can see from my TODO, I'm unsure what to do if there's an error. Do I to put "e.Canceled = True", and if so, what does it do? Also, how can I tell the user what the error (ex.Message) is without a postback? (Or does this auto postback?) Assuming it doesn't postback, the best I can determine is to have a control on the form to write the error to in red font, but management doesn't like that idea. They'd rather I pop up an alert, but not sure that's possible.
Any suggestions? And am I going about this the right way to manually save the data?
9 Answers, 1 is accepted
Regarding the e.Canceled, as documented in our "Server-side API" article, it is applicable with enabled automatic CRUD operations when you need to cancel the operation after failed validation for example.
As for informing the user, you can place a simple Label control on your page and set the error message to the Text property of the Label. You can then clear the message after some time on client-side or clear it on the next postback (within Page's Load event).
Hope this helps.
How can I trigger a postback if grdPODetails_BatchEditCommand is successful, but don't if I had an error caught in the Catch ex as Exception area?
FYI, the button that calls SavePO() has the click event set to "SavePO(); return false;" because if there is an error, I don't want a postback -- only if the save if successful. How can that be done?
Maybe I'm going about it a bit wrong, but it seems there must be a way to use a Batch Grid to manually save the data with a button outside the grid, and only reload the page if it's successful.
Please note that in order for the data to be sent to the server there should be a postback. This means that the postback happens when the changes are sent to the server. The validation is performed after that.
In my grdPODetails_BatchEditCommand proc above, in the Catch portion, is there any way to make ex.Message appear as a popup to the user? I can't see how, as it's server-side, but I'm asking as management wants to know.
if you would like to use the BatchEditCommand event to add code to be executed client-side you can use the following approach:
Still, I would point out that postback will happen when sending the information to the server. However, with adding the logic from above you can alert the user if validation of the data was successful.
That's pretty slick, and seems to work to show my error message! And there's no possible drawbacks to this? Such as the message appearing a 2nd time during the next postback?
The message should be displayed only after the BatchEditCommand event was raised. It should not be shown after other actions with the grid (e.g. paging).
I implemented the change, but had a user click save a 2nd time, and that time they got 2 error messages -- the 1st message followed by the 2nd. Clicked again and got all 3 error messages, one after the other, etc. So apparently this tacks it on to the existing script each time?
This could be observed if the grid is Ajax-enabled. If this is the case you can try the following code. It is working as expected on my end.