Cancel button is not working anymore after a failed save.

Cancel button is not working anymore after a failed save.

Old forum URL: forums.lhotka.net/forums/t/7206.aspx


alef posted on Wednesday, July 01, 2009

Steps in the projecttracker application to reproduce the problem
- Edit a project
- Change some fields
- Stop the database to simulate an error
- Click on Apply
- An error will occur as expected because we stopped SQL server
- Start the database again
- When we try to cancel the changes (_project.CancelEdit();) nothing happens

I should expect that the cancel should still work because the save operation didn't succeeded, so the user should still be able to cancel.


RockfordLhotka replied on Wednesday, July 01, 2009

You can do this, but it is relatively expensive, which is why it isn't the default behavior.

When you save an object, CSLA does this (by default):

  1. ApplyEdit() to get edit level to 0
  2. Clone original object
  3. Save clone
  4. If Save succeeds, return new object
  5. If Save fails, return original object

If you want the Cancel button to still be available when Save fails, you'll need another clone of the object before ApplyEdit() is called. Since cloning an object graph isn't free (in terms of performance), that isn't the default behavior - but you can certainly do that clone yourself.

RockfordLhotka replied on Wednesday, July 01, 2009

I guess I should be more clear in terms of timing.

The other issue is that the UI does the ApplyEdit() - before CSLA gets the object. So it is actually your UI code that needs to do the clone before calling ApplyEdit() and (probably) before unbinding the object from the UI's data binding.

Copyright (c) Marimer LLC