I have a webdatagrid where I am able to delete rows without any problem. I have also got the server side RowDeleting event working,which does a dependency check, and cancels the delete if its not permitted. However I'd like to notify the user that this happened - but because the event is asynchronous, I can't update anything else on the page to set a message??
Have you a suggestion as to how I can either:
- somehow pass back a message to the client and display it during the sync call or
- handle the entire thing from the client, including calling an OnDeleting method and acting on its reply (allowed or not allowed) - and thus displaying message using Confirm()/Alert()...etc.
Thanks. As you were writing this I solved it - I wanted to use a WebDialog control so messaging was consistent in appearance throughout (and so I could have more complex HTML formatting)- my problem was that it had to be wrapped inside the same updatepanel as the grid...sigh.
The problem with handling RowDeleted is that it doesn't account for messages explaining to the client why a delete was cancelled (eg: dependency clash). There needs to be a RowDeleteCancelled client event, or rowDeleted needs to handle both scenarios, with a param telling you if it was actually cancelled...
The same event "gap" is present in almost all the client side events which can be cancelled - no client side vent exists to detect that scenario.
Hi,
In your server side rows deleting event, when you cancel the delete on a row, I would suggest setting some sort of error message by setting e.Row.Tag. Next, you will want to handle the client side RowDeleted event off of the grid's editing core. You can then access the canceled rows' ids. From those, you can get the row objects, and then access the tag that you set in the server side event. Code similar to this would work. You could throw an alert with the message or update some other element in the DOM.
function rowsDeleted(sender, e) { var grid = ig_controls["WebDataGrid1"]; var textBox = document.getElementById("ErrorMessage"); var rowCount = e.get_canceled_rowIDPairs().length; for (var i = 0; i < rowCount; i++) { var newMessage = grid.get_rows().get_rowFromIDPair(e.get_canceled_rowIDPairs()[i]).get_tag(); message = message + newMessage + "\n"; } textBox.value = message; }
Hopefully this gets you rolling in the correct direction.
regards,David Young