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

Problem getting value with RadNumericTextBox with CompareValidator

2 Answers 138 Views
Input
This is a migrated thread and some comments may be shown as answers.
Dominique
Top achievements
Rank 1
Dominique asked on 04 Mar 2014, 04:02 PM
Hi,

I would like to use a CompareValidator on a RadNumericTextbox control (2012.2.904.40).

Everything is setup fine.

But it doesn't works as excepted, while debugging I see that there is a problem in the telerik JS method : ValidatorGetValue(val.controltovalidate).

This method contains :
ValidatorGetValue=function(a){
      var b=document.getElementById(a);
      if(typeof(b.RadInputValidationValue)=="string"){
           return b.RadInputValidationValue;
      }
      else{
           return ValidatorGetValue_Original(a);
      }
}

In my case b.RadInputValidationValue is always an empty string even if there is some value inside, so typeof(b.RadInputValidationValue)=="string" is always true but always return and empty string, if I try in debugging ValidatorGetValue_Original(a) it returns me the right value ! 

2 Answers, 1 is accepted

Sort by
0
Dominique
Top achievements
Rank 1
answered on 04 Mar 2014, 05:44 PM
Ok I found why, If I can't use a CompareValidator on a RadNumericTextBox with MinValue/MaxValue setted.
For example, when I set the MaxValue to 10 and I put 11 in the field then RadInputValidationValue is empty.


I don't know if it's the correct behavior but this is a problem when we want to also use a CompareValidator on the field.

Si is it a bug or not ?
0
Viktor Tachev
Telerik team
answered on 07 Mar 2014, 12:24 PM
Hello Dominique,

The value entered in a RadNumericTextbox control is not submitted if it is out if the range specified by MinValue and MaxValue properties. This is the way the control was built to work. In order to achieve the behavior you describe you could use different approaches depending on your current requirements.

You could add a RequiredFieldValidator for the RadNumericTextBox. This way postback will be prevented if the value entered is not between MinValue and MaxValue. Check the following code snippet for illustration.

<telerik:RadNumericTextBox ID="RadNumericTextBox2" runat="server" MinValue="1" MaxValue="10" AllowOutOfRangeAutoCorrect="false">
</telerik:RadNumericTextBox>
<telerik:RadNumericTextBox ID="RadNumericTextBox3" runat="server" MinValue="1" MaxValue="10" AllowOutOfRangeAutoCorrect="false" >
</telerik:RadNumericTextBox>
<asp:RequiredFieldValidator ErrorMessage="errormessage" ControlToValidate="RadNumericTextBox3" runat="server" />
 
<asp:CompareValidator ID="CompareValidator1" runat="server"
    ControlToValidate="RadNumericTextBox3" ControlToCompare="RadNumericTextBox2"
    Operator="LessThan" Type="Double"
    ErrorMessage="CompareValidator error"></asp:CompareValidator>
 
<asp:Button Text="Click" runat="server" />

Another possible approach is to use a CustomValidator control and handle the validation manually. You could add custom client- and server-side  validation methods.

On a side note, the version of the controls you are using is rather old. It is always recommended to use the latest version of our controls as it includes different improvements and new features.

Regards,
Viktor Tachev
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Tags
Input
Asked by
Dominique
Top achievements
Rank 1
Answers by
Dominique
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or