Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling Validation when leaving controls in web form
Message
De
09/09/2010 13:44:49
 
 
À
08/09/2010 17:02:27
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01479579
Message ID:
01480694
Vues:
50
>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;
>
>}
>
>

I've tried it like this, but I still get the same error :(

Here's my actual code:

in my PolicyRider.Partial.cs:
        public string ValidateSumAssuredMaxMin(Guid? planPK, decimal? sumAssured)
        {
            // Get the Plan for the specified PlanPK
            Plan oPlan = new Plan();
            oPlan.GetPlanByPlanPK((Guid)planPK);

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

        }
In my PolicyRiderRules.Partial.cs:
        public string ValidateSumAssuredMaxMin(Decimal? sumAssured, Decimal? min, Decimal? max)
        {
            string message = null;
            // check that the sum assured meets the min and max sum assured requirements
            if (min > (Decimal)sumAssured
                    || max < (Decimal)sumAssured)
            {
                message = "Rider Sum Assured must be between " + min.ToString() + " and " + max.ToString();
                this.AddErrorProviderBrokenRule("SumAssured", message);
            }
            return message;
        }
In my PolicyEdit.aspx.cs:
        protected void txtRiderSumAssured_TextChanged(object sender, EventArgs e)
        {
            TextBox thisTextBox = (TextBox)sender;
            this.oPolicyRider.Rules.ClearAll();
            GridViewRow gvr = (GridViewRow)thisTextBox.Parent.Parent;
            if (this.oPolicyRider.ValidateSumAssuredMaxMin((Guid)this.oPolicyRider.DataSet.Tables[0].Rows[gvr.RowIndex]["RiderFK"], decimal.Parse(thisTextBox.Text)) != null)
            {
                // show the message somehow
            }

            this.CalculateRiderPremium(true, gvr);
            this.SetFocus(gvr.Cells[3].Controls[1]);
        }
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform