Reputation: 153
I want to take only positive number in my RadNumericTextBox.
I tried
<telerik:RadNumericTextBox MinValue="0" TabIndex="8" ID="txtPositiveNumericField" runat="server" Width="98%">
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
But till now it takes negative number.
Upvotes: 1
Views: 1427
Reputation: 6455
What Telerik library version are you using? In my case, all I needed to do is
just apply MinValue
attribute and set it to 0. I added DataType
attribute as well, just to be specific about what type of numeric value I want.
<telerik:RadNumericTextBox MinValue="0" TabIndex="8" DataType="System.Int32" ID="txtPositiveNumericField" runat="server" Width="98%">
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
Upvotes: 3
Reputation: 153
I find a solution by using javascript function. Add ClientEvents for OnKeyPress in RadNumericTextBox and for this event define a javascript function.
<telerik:RadNumericTextBox MinValue="0" TabIndex="8" ID="txtPositiveNumericField" runat="server" Width="98%">
<NumberFormat DecimalDigits="0" />
<ClientEvents OnKeyPress="NumberFieldKeyPress" />
</telerik:RadNumericTextBox>
And javascript function:
function NumberFieldKeyPress(obj ,arg)
{
if(arg.get_keyCode()==45)
{
alert("This field only takes positive number.");
arg.set_cancel(true);
}
}
But if there have any trick without javascript please put your answer.
Thanks ..
Upvotes: 1