RadNumericTextbox Positive Decimals greater than zero only and throw error otherwise

3 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 26 May 2011 Link to this post

    Hi

    I've seen a few threads similar in the forums but not exactly what I want.
    1) How do I set a minimum value greater than 0? Anything bigger is fine, eg: 0.1, 0.00756, 0.0000111. Currently I'm setting minvalue to 0.01, but that seems like a fudge to me.
    2) If the user tries to enter a negative value it rounds it to the minimum value (ie 0.01). Can the input handle this to prevent negative numbers? I'd rather warn the user with an error message, or the current little warning symbol that flashes up. Then show a blank textbox rather than the minvalue.

    Cheers,
    Jeremy
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 May 2011 Link to this post

    Hello Jeremy,
    Give a try with the following aspx and js function to achieve your requirement which worked as per your requirement at my end.
    aspx:
    <telerik:RadNumericTextBox ID="txtLatitude" Enabled="false" runat="server" MaxLength="8"
    MinValue="0" NumberFormat-KeepNotRoundedValue="true" NumberFormat-DecimalDigits="10"
    NumberFormat-AllowRounding="false" DataType="System.Decimal">
       <ClientEvents OnKeyPress="OnKeyPress" />
    </telerik:RadNumericTextBox>

    Client side:
    function OnKeyPress(Sender, args)
     {
           if (args.get_keyCode() == 45)
          {
               alert("-ve numbers are not allowed!!");
               args.set_cancel(true);       
           }
     }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 26 May 2011 Link to this post

    Thanks Shinu! That keypress was pretty nifty for stopping negative values - but I found something even better that also checks if it is greater than zero: a compare validator :)

    <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Skin="Vista" NumberFormat-DecimalDigits="2" DataType="System.Decimal" DbValue='<%# Eval("TOTAL_METRES") %>'></telerik:RadNumericTextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadNumericTextBox1" ErrorMessage="*" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="RadNumericTextBox1" ErrorMessage="*" Display="Dynamic" ForeColor="Red" ValueToCompare="0" Operator="GreaterThan"></asp:CompareValidator>
Back to Top