Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
270
Validating the match between two text boxes
posted

My form has two text boxes: one named "New Password" and another named "Confirm Password"

I am trying to use validator to validate the match between the two passwords.

In CreateOperatorCondition function, I use

" thePasswordSettings.Condition = New  Infragistics.Win.OperatorCondition _ (Infragistics.Win.ConditionOperator.Equals, Me.utxtNewPassword.Text, True)"

but it does not work.

Just wonder can I use validator to compare value in another text box?

Thank you for you reply.

Parents
  • 69832
    Suggested Answer
    Offline posted

    The problem with that approach is that the value of the 'utxtNewPassword' control's text at that moment is assigned to the OperatorCondition's CompareValue. The string datatype's assignment operator basically makes a copy of the string, so you don't have a "live reference" to the TextBox's Text property value.

    You can do this by assigning a custom ICondition implementation to the ValidationSettings.Condition property, as demonstrated by the following code example:

    public class TextBoxCompareCondition : ICondition
    {
        private TextBox otherControl = null;
        public TextBoxCompareCondition( TextBox otherControl )
        {
            this.otherControl = otherControl;
        }

        #region ICondition Members

        bool ICondition.Matches(object value, IConditionContextProvider contextProvider)
        {
            string text = value as string;
            return string.Equals(text, this.otherControl.Text);
        }

        event EventHandler ICondition.PropertyChanged
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        #endregion

        #region ICloneable Members

        object ICloneable.Clone()
        {
            throw new NotImplementedException();
        }

        #endregion
    }

Reply Children