I need to implement a confirmable validation rules mechanism, which would mimick regular validation rules in WinForms
but in Web environment
when the rule is broken, the user gets a confirmation message "Are you sure to save it?"
As many objects in my project are commited from within the code, I cannot simply set the confirmation messages as it is shown in the last post of http://www.devexpress.com/Support/Center/Question/Details/Q380252 thread.
In my opinion the best direction in my case is to use ObjectSpace_Committing event. Can you agree?
I am trying the following code:
C#public class WebConfirmableRuleCriteriaViewController : ViewController
{
protected override void OnActivated() {
base.OnActivated();
View.ObjectSpace.Committing += ObjectSpace_Committing;
}
protected override void OnDeactivated() {
View.ObjectSpace.Committing -= ObjectSpace_Committing;
base.OnDeactivated();
}
protected void ObjectSpace_Committing(object sender, System.ComponentModel.CancelEventArgs e)
{
foreach (var modifiedObject in View.ObjectSpace.ModifiedObjects)
{
if (View.ObjectSpace.IsObjectToSave(modifiedObject))
{
// if(modifiedObject has OptionalRuleAttribute && the rule is broken)
{
WebWindow.CurrentRequestWindow.RegisterClientScript("teset", "if(confirm('Are you sure to save? The rule is broken.')) { alert('Confirmed! Want to invoke ObjectSpace.CommitChanges.'); } else { alert('Cancelled! No save...'); } ");
e.Cancel = true;
}
}
}
}
}
Questions:
-
I really doubt it, but is it possible to synchronously wait for the user until he confirms the JS dialog and then continue the server code?
And get the user's answer to server side?
The problem appears when I click Save&Close button: after the commit is cancelled, view is closed and the objectSpace is lost. So when the user confirms JS dialog I already have the changes lost. -
How to invoke ObjectSpace.CommitChanges via Javascript?