This is a migrated thread and some comments may be shown as answers.

RadTextBox with asp CompareValidator

3 Answers 135 Views
Input
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 12 Nov 2008, 11:02 AM
Hello,

I've placed two RadTextBoxes on a page together with a CompareValidator (Operator="Equal") with the option ValidateEmptyText="true". But the validator doesn't trigger when the value is empty. It doesn't work both client and server side.

The problem can be reproduces with the following code:

Value 1: <telerik:RadTextBox ID="txtPasswordFirst" runat="server" TextMode="Password"></telerik:RadTextBox> 
<br /> 
Value 2: <telerik:RadTextBox ID="txtPasswordSecond" runat="server" TextMode="Password"></telerik:RadTextBox> 
<asp:CompareValidator ID="valPasswordEqual" runat="server" EnableClientScript="false" ControlToValidate="txtPasswordSecond" ControlToCompare="txtPasswordFirst" Text="Values are not equal" Operator="Equal" ValidateEmptyText="True"></asp:CompareValidator> 
<br /> 
<asp:Button runat="server" Text="Submit" ID="btnSubmit" OnClick="btnSubmit_Click" /> 
<br /> 
<asp:Label runat="server" ID="lblRes" Text="Click to validate"></asp:Label> 
 
<script runat="server"  > 
Protected Sub btnSubmit_Click(ByVal sender as Object, ByVal e as EventArgs) 
  lblRes.Text = String.Format("IsValid: {0}", Page.IsValid) 
End Sub 
</script> 
 

Regards,
Paul

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 12 Nov 2008, 11:41 AM
Hello Paul,


By using the CompareValidator server control, you guarantee that txtPasswordFirst.Text and txtPasswordSecond.Text are equal strings. If they are not equal, the page returns an error message . If they are equal, your page submits as valid. The ValidateEmptyText property allows developers to evaluate the results of a CustomValidator control.

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul
Top achievements
Rank 1
answered on 12 Nov 2008, 12:09 PM
You are correct, the ValidateEmptyText-property is of the CustomValidator, I just mixed them up.
But my problem still exists, if I only enter a value to txtPasswordFirst and hit submit, the page is still valid. But I expect it to be invalid because the values are not equal.

After some testing with just the default TextBox-control, the CompageValidator only does it work, when it has assigned a value (that's why I placed (the non-existing property) ValidateEmptyText to true).
This will be solved when I add a RequiredValidator to the ControlToCompage-field.
But because these field are not always required in my situation, I'm going to add a CustomValidator to compare the values (this will work, because there the ValidateEmptyText-property DOES work).

Thanks for you help.

Kind regards,
Paul
0
Missing User
answered on 12 Nov 2008, 12:26 PM
Hello Paul,


I am glad to hear you have found a solution to this issue. Do not hesitate to contact us if you need any further assistance!

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Input
Asked by
Paul
Top achievements
Rank 1
Answers by
Missing User
Paul
Top achievements
Rank 1
Share this question
or