RadNumericTextBox Allowing Decimals

2 posts, 0 answers
  1. Brian Mains CompInc
    Brian Mains CompInc avatar
    3 posts
    Member since:
    Nov 2008

    Posted 20 Mar 2009 Link to this post

    Hello,

    I'm trying to prevent numbers like:

    500.10

    I want only amounts like:

    500

    entered.

    I setup the RadNumericTextbox with:

    DecimalDigits="0"
    DataType="System.Int32"
    MinValue="0"

    And even though I have this, it still allows 500.10.  Also, ValueChanged seems to fire after the RadNumericTextBox adjusts the value to 500.  So User enters 500.10, the ValueChanged client-side event fires, and the value is adjusted to 500 in RadNumericTextBox.

    Is there a way to get the value to adjust before this event fires, or is there a better event to tap into?

    Thanks.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Mar 2009 Link to this post

    Hello Brian,

    One suggestion is preventing the user from entering decimal values. I tried to get the Key pressed and cancel the event if tried to enter the decimal.

    ASPX:
    <telerik:radnumerictextbox id="RadNumericTextBox1" ToolTip="Decimals not allowed" MinValue="0" runat="server" DataType="System.Int32">          
        <NumberFormat DecimalDigits="0" /> 
        <ClientEvents OnValueChanged="OnValueChanged" OnKeyPress="OnKeyPress" /> 
    </telerik:radnumerictextbox> 

    JavaScript:
    <script type="text/javascript">  
    function OnValueChanged()  
    {  
        alert('Value Changed');  
    }  
    function OnKeyPress(sender, eventArgs)  
    {  
       var c = eventArgs.get_keyCode();  
       if (c ==46) // Typed .  
       {  
         eventArgs.set_cancel(true);   
       }  
    }  
    </script> 

    Thanks,
    Princy.
Back to Top