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

RadNumericTextbox Positive Decimals greater than zero only and throw error otherwise

2 Answers 313 Views
Input
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 26 May 2011, 05:46 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 May 2011, 11:15 AM
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.
0
Jeremy
Top achievements
Rank 1
answered on 27 May 2011, 04:52 AM
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>
Tags
Input
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jeremy
Top achievements
Rank 1
Share this question
or