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 17:02:27
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
08/09/2010 14:38:39
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01479579
Message ID:
01480617
Views:
61
Frank,

The answer depends on if you will use the validation during the save as well. If so then I would do it the way I mentioned and I will paste in below. If this validation will not be used during the save ever, then I would just put this code in your business object and change the name to something other than Validate. Maybe VerifySumAssuredMaxMin() that way it isn't confused with the pre save validation. Just a thought.

If you will use the Validation on save and I presume you would then I would do this.
In your business object
public string ValidateSumAssuredMaxMin(Guid? planPK, decimal? sumAssured)
{
       // Get the Plan for the specified PlanPK
	this.GetPlanByPlanPK((Guid)planPK);

	// Call the validate method in the Rules object
	return this.Rules.ValidateSumAssuredMaxMin(this.Entity.MinSumAssured, this.Entity.MaxSumAssured, sumAssured);

}
Then in your Rules and can still be called from the CheckRulesHook method before a save.
public string ValidateSumAssuredMaxMin(decimal minSumAssured, decimal maxSumAssured, decimal sumAssured)
{
	string message = null;

	if (minSumAssured > sumAssured || maxSumAssured < sumAssured)
	{
		message = "Rider Sum Assured must be between " + minSumAssured.ToString() +
			" and " + maxSumAssured.ToString();

		this.AddErrorProviderBrokenRule("SumAssured", message);
	}
	return message;

}
>>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
>
>Tim,
>
>if I am doing something out of the ordinary I would prefer to do it the recommended way. So rather than trying it your suggested way, what would be the normal way to validate a field based on another field? In this case can I assume the Min and MaxSumassured are available without having to get them by creating a new BO?
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform