Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling Validation when leaving controls in web form
Message
From
08/09/2010 12:30:42
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
08/09/2010 10:51:23
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01479579
Message ID:
01480587
Views:
44
Hi Frank,

>Here's the code:
>
>
        public string ValidateSumAssuredMaxMin(Guid? planPK, decimal? sumAssured)
>        {
>            string message = null;
>                Plan oPlan = new Plan();
>                oPlan.GetPlanByPlanPK((Guid)planPK);
>                // check that the sum assured meets the min and max sum assured requirements
>                if (oPlan.Entity.MinSumAssured > (decimal)sumAssured
>                        || oPlan.Entity.MaxSumAssured < (decimal)sumAssured)
>                {
>                    message = "Rider Sum Assured must be between " + oPlan.Entity.MinSumAssured.ToString() + " and " + oPlan.Entity.MaxSumAssured.ToString();
>                    this.AddErrorProviderBrokenRule("SumAssured", message);
>                }
>            return message;
>        }
>
>This is called from a textbox that is in a grid displaying/editing the child business object.

This is a bit of an odd answer, so bear with me. The business rules object is normally accessed via the business object and in this case you are accessing the rules object this way but then in the rules object you are creating a new business object. I did not trace through this to see what happens, but I would recommend a different approach. Maybe this.

Put a method in your business object that you call instead of your rules object that can begin the validation process. What that method would do is GetPlanByPlanPK and then once the record is retrieved, let that method call the rules.ValidateSumAssuredMaxMin method. I would take the code out of the validate method which creates a business object and retrieves data.

I hope that made sense, and let me know how that turns out.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform