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.
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}
Thank you for your reply. Technically, how do I assign a custom ICondition implementation to the ValidationSettings.Condition property? By the way, I am in vb.net. Not sure the codes you provide will make any differences.
bcsite said:Technically, how do I assign a custom ICondition implementation to the ValidationSettings.Condition property?
You just assign an instance of a class that implements that interface (for example the one I posted previously) to the property. The code I posted is written in C#, but it is fairly simple to convert it to VB. You could also just declare a class that implements that interface in VB, right click on the interface name and select one of the menu options for "implement interface".