Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Intertrelated controls
Message
De
20/09/2010 15:33:03
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
20/09/2010 14:46:36
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01482058
Message ID:
01482070
Vues:
54
Frank,

For starters, I would put all that code in one method. You can create a single TextChanged event handler and point both text boxes to the same one. You will know which one raised the event by creating a textbox from the source object. Something like this to get you started.

What is the tab order between these two controls. If they change one and this event fires, does it move right to the other?
protected void txtPolicyExpiry_TextChanged(object sender, EventArgs e)
{
     mmTextBox source = (TextBox)sender;
     if (source.ID == "txtExpiryDate")
     {
          // Do one thing
     }
     else
     {
          // Do the other
     }
}
Tim

>Hi,
>
>I have two controls on an ASP.NET page. One is a Date of maturity and the other is the Age at maturity. The requirement is that when the Date of Maturity changes, the Age at Maturity should reflect the new date and vice versa (if the age is changed then the date should reflect the new age).
>
>I have it working so that my date is defined like this:
>
>
<mm:mmTextBox ID="txtExpiryDate" runat="server" BindingSource="Policy" BindingSourceMember="ExpiryDate"
>DisplayFormat="{0:d}" Width="79px" CssClass="date" AutoPostBack="true" OnTextChanged="txtExpiryDate_TextChanged"></mm:mmTextBox>
>
><mm:mmTextBox ID="txtRetirementAge" runat="server" BindingSource="Policy" BindingSourceMember="RetirementAge"
>Width="54px" AutoPostBack="true" OnTextChanged="txtRetirementAge_TextChanged"></mm:mmTextBox>
>
>My code is this:
>
>
        protected void txtExpiryDate_TextChanged(object sender, EventArgs e)
>        {
>            // update Age at retirement
>            if (this.oPlan.Entity.PlanTypeFK == 1)  // Annuity
>            {
>                // work out age at retirement
>                this.txtRetirementAge.Text = this.oClient.GetAgeNearest(this.oClient.Entity.DateOfBirth, Convert.ToDateTime(this.txtExpiryDate.Text)).ToString();
>            }
>
>        }
>
>        protected void txtRetirementAge_TextChanged(object sender, EventArgs e)
>        {
>            // update Date of expiry/maturity
>            if (this.oPlan.Entity.PlanTypeFK == 1)  // Annuity
>            {
>                // work out the age difference between age at issue and retirement age
>                Int16 ageDiff = (Int16)(Convert.ToInt16(this.txtRetirementAge.Text) - oPolicy.Entity.AgeAtIssue);
>
>                // add the difference to the issue date
>                DateTime dt = (DateTime)this.oPolicy.Entity.IssueDate;
>                dt = dt.AddYears(ageDiff);
>                this.txtExpiryDate.Text = dt.ToString();
>            }
>        }
>
>
>This works fine if I change the date, the age gets recalculated properly. But if I change the age, and I set a breakpoint in xtRetirementAge_TextChanged, it is showing me that the this.txtRetirementAge.Text is the old value, not the value I just entered!
>
>I'm wondering if it has to do with the age changing, which changes the date which changes the age (and so on).
>
>How would you suggest I approach this?
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform