I am catching the error here, this works cuz stepping through code.
Session[
"currentEmployee"] = obj.Save();e.RowsAffected = 1;
}
catch (ValidationException ve){
this.ErrorLabel.Text = ve.Message; this.ErrorLabel.Text += ve.Data.Keys.ToString(); this.ErrorLabel.Text += ve.Data.Values;e.RowsAffected = 0;
}
Here is my custom Validation Rule:
private bool ValidHourlyEntry(object target, Csla.Validation.RuleArgs e){
switch (hourly){
case "S": case "H": case "C":e.Description =
"Valid Entries: S -Salary, H -Hourly, C -Commission!"; return true; break; default: return false; break;}
}
I keep getting a generic error message:
Object is not valid and can not be savedSystem
Would like to display the custom error message e.Description !!
Thanks,
Appreciate your help
Don
I would think that you should just check if it is valid (Object.IsValid) before saving the object. You can see the specific rules that are broken by checking the BrokenRulesCollection (assuming CSLA v.2.0.3) on the object you are validating.
Could you please post me sample code to do this? I just searched the entire book for any instance of e.Description being displayed in the ui and cannot find a sample. Still new to Csla, so this is probably a very simple question.
I've not worked with CSLA and Web Forms, but I am not sure that it matters...
if (!obj.IsValid) lblErrors.Text = obj.BrokenRulesCollection.ToString(); else Session["CurrentObject"] = obj.Save();
Hope that clears it up.
Another thing... Set the error description only if the validation fails. Right now, you are setting the error description if the validation passes.
Copyright (c) Marimer LLC