Problem getting value with RadNumericTextBox with CompareValidator

3 posts, 0 answers
  1. Dominique
    Dominique avatar
    2 posts
    Member since:
    Mar 2014

    Posted 04 Mar 2014 Link to this post


    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 :
          var b=document.getElementById(a);
               return b.RadInputValidationValue;
               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. Dominique
    Dominique avatar
    2 posts
    Member since:
    Mar 2014

    Posted 04 Mar 2014 in reply to Dominique Link to this post

    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 ?
  3. Viktor Tachev
    Viktor Tachev avatar
    2499 posts

    Posted 07 Mar 2014 Link to this post

    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 ID="RadNumericTextBox3" runat="server" MinValue="1" MaxValue="10" AllowOutOfRangeAutoCorrect="false" >
    <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.

    Viktor Tachev

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

Back to Top