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.
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".
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.
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}
Hello,
If I understand correctly you create and attach the condition operator. What you need to do is to attach the NewPassword to the Validator also and add a condition operator to the control that you want to validate, and perform Validate. The sample code bellows shows how to attach Validator to a TextBox and condition to and other TextBox value:
ValidationSettings validationSettings = ultraValidator1.GetValidationSettings(NewPassword);
validationSettings.Condition = new OperatorCondition(ConditionOperator.Equals, ConfurmPassword .Text, true);
You may lock at the fallowing sample how to validate :
http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.Misc.v8.2~Infragistics.Win.Misc.ValidationSettings~Condition.html
I hope this helps.
Dimi
Developer Support Engineer
Infragistics Inc