How do i display e.Description in UI

How do i display e.Description in UI

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


dstarkey posted on Monday, October 16, 2006

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

ChristianPena replied on Monday, October 16, 2006

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.

 

dstarkey replied on Monday, October 16, 2006

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.

dstarkey replied on Monday, October 16, 2006

Also want to mention that the UI is a web form.

ChristianPena replied on Monday, October 16, 2006

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.

RockfordLhotka replied on Monday, October 16, 2006

Look in Chapter 10, at the PTWeb project - specifically the ProjectEdit.aspx page. There's code in that page to catch the validation exception and display all the validation rule descriptions from the object by using the IDataErrorInfo interface.

Copyright (c) Marimer LLC