RadNumericTextBox and CompareValidator

11 posts, 2 answers
  1. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 17 Feb 2010 Link to this post

    Hi,

    I try to validate two RadNumericTextBox control by CompareValidator:

    <telerik:RadNumericTextBox id="NumberMinValueTextBox" runat="server" /> 
    <telerik:RadNumericTextBox id="NumberMaxValueTextBox" runat="server" /> 
    <asp:CompareValidator ID="NumberMinMaxValidator" runat="server" ErrorMessage="The max value couldn't be less than the min value." Operator="GreaterThanEqual" ControlToCompare="NumberMinValueTextBox" ControlToValidate="NumberMaxValueTextBox" ValidationGroup="NumberField" Display="Dynamic" /> 

    It works ok only, when the compared values in the both min and max control contain the same number of digits.
    (i.e min = 1, max = 9  or min = 10, max = 25 etc.)

    But when I enter e.g.  '12' to min control and '102' validation failed. It looks that the max value is trimmed from '102' to '10' then 12 > 10 and validatio failed.

    What am I doing wrong? Thanks in advance.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2010 Link to this post

    Hello Michal,

    I also experienced same issue when tried your code. I achieved same functionality by using CustomValidator instead of CompareValidator. Here is the code that I tried. Hope this helps.

    ASPX:
     
    <telerik:RadNumericTextBox ID="NumberMinValueTextBox" runat="server" /> 
    <telerik:RadNumericTextBox ID="NumberMaxValueTextBox" runat="server" /> 
      
    <asp:CustomValidator ID="CustomValidator1" ControlToValidate="NumberMaxValueTextBox" 
        runat="server" ClientValidationFunction="ClientValidate" ErrorMessage="The max value couldn't be less than the min value."
    </asp:CustomValidator> 

    JavaScript:
     
    <script type="text/javascript"
        function ClientValidate(source, arguments) { 
            var min = $find('<%= NumberMinValueTextBox.ClientID %>'); 
            var max = $find('<%= NumberMaxValueTextBox.ClientID %>'); 
            if (min.get_value() > max.get_value()) { 
                arguments.IsValid = false
            } 
        } 
    </script> 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 17 Feb 2010 Link to this post

    Thank you, of course your code solved my problem and I know that I can use customvalidator.
    But as you wrote above there is needed some javascript code and also some function on server side for validation when the javascript support is disabled. That's why I wanted to use a comparevalidator :)

    Is there some bug in CompareValidator control or RadNumericTextBox ?
  5. Answer
    Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 18 Feb 2010 Link to this post

    Hello,

    The CompareValidator does not work as expected, because by default it compares strings:

    http://msdn.microsoft.com/en-us/library/system.web.ui.mobilecontrols.comparevalidator.type.aspx

    Please set Type="Double" and there will be no need to use a custom validator.

    Regards,
    Dimo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 01 Jul 2010 Link to this post

    Hi,

    Now, I have a problem when the RadNumericTextBox control has set the comma (,) decimal separator and the CompareValidator does not work as expected. Any ideas?

    Regards,
  7. Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 05 Jul 2010 Link to this post

    Hi Michal,

    I cannot observe a problem with CompareValidator and RadNumericTextBoxes with comma as a decimal separator. Can you provide a simple test page?


    Greetings,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 05 Jul 2010 Link to this post

    Hi,

    Here is sample:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Culture="auto" UICulture="auto" %> 
     
    <%@ Register assembly="Telerik.Web.UI, Version=2010.1.519.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
         
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox2" Runat="server"
                <NumberFormat DecimalSeparator="," DecimalDigits="2" /> 
            </telerik:RadNumericTextBox> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server"
                <NumberFormat DecimalSeparator="," DecimalDigits="2" /> 
            </telerik:RadNumericTextBox> 
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="RadNumericTextBox2" ControlToCompare="RadNumericTextBox1" Operator="LessThan" Type="Double" 
                ErrorMessage="CompareValidator"></asp:CompareValidator> 
        </div> 
        </form> 
    </body> 
    </html> 

    and codebehind

    public partial class _Default : System.Web.UI.Page 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            System.Globalization.CultureInfo info = System.Globalization.CultureInfo.CreateSpecificCulture("en"); 
     
            System.Threading.Thread.CurrentThread.CurrentUICulture = info; 
            System.Threading.Thread.CurrentThread.CurrentCulture = info; 
     
        } 

    Notice that a user's culture is set up to english (bescause all of the resource have to be displayed in English language), but there are some customizable fields that could have a comma as separator.

  9. Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 06 Jul 2010 Link to this post

    Hi Michal,

    The provided sample page works as expected on my side. I tested in Firefox and Internet Explorer. See the attached screeshot.

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Globalization.CultureInfo info = System.Globalization.CultureInfo.CreateSpecificCulture("en");
     
            System.Threading.Thread.CurrentThread.CurrentUICulture = info;
            System.Threading.Thread.CurrentThread.CurrentCulture = info;
     
        }
         
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <telerik:RadNumericTextBox ID="RadNumericTextBox2" Runat="server">
        <NumberFormat DecimalSeparator="," DecimalDigits="2" />
    </telerik:RadNumericTextBox>
    <telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server">
        <NumberFormat DecimalSeparator="," DecimalDigits="2" />
    </telerik:RadNumericTextBox>
    <asp:CompareValidator ID="CompareValidator1" runat="server"
        ControlToValidate="RadNumericTextBox2" ControlToCompare="RadNumericTextBox1"
        Operator="LessThan" Type="Double"
        ErrorMessage="CompareValidator"></asp:CompareValidator>
     
    <br /><br /><br />
     
    <telerik:RadNumericTextBox ID="RadNumericTextBox3" Runat="server">
        <NumberFormat DecimalSeparator="," DecimalDigits="2" />
    </telerik:RadNumericTextBox>
    <telerik:RadNumericTextBox ID="RadNumericTextBox4" Runat="server">
        <NumberFormat DecimalSeparator="," DecimalDigits="2" />
    </telerik:RadNumericTextBox>
    <asp:CompareValidator ID="CompareValidator2" runat="server"
        ControlToValidate="RadNumericTextBox3" ControlToCompare="RadNumericTextBox4"
        Operator="LessThan" Type="Double"
        ErrorMessage="CompareValidator"></asp:CompareValidator>
     
     
    </form>
    </body>
    </html>


    All the best,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 06 Jul 2010 Link to this post

    Ok, but enter some digits different then zero after separator and add

    Culture="auto" UICulture="auto" 

    in the <%@ Page Language="C#" %> declaration.



  11. Answer
    Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 06 Jul 2010 Link to this post

    Hello Michal,

    Thanks, now I reproduced the problem. However, the same behavior is exhibited with standard asp:TextBoxes if you use comma as a decimal separator. So the problem is the culture and separator inconsistency and the way the validator interprets those. Please consider changing the culture/separator settings.

    Best wishes,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Michal Siudyka
    Michal  Siudyka avatar
    11 posts
    Member since:
    Nov 2009

    Posted 09 Jul 2010 Link to this post

    Hi Dimo,

    Thanks, so I have to use a custom validator.

    Regards,
    Michał
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017