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

Restrict '-' to type be typed in a RadNumericTextBox.

2 Answers 69 Views
Input
This is a migrated thread and some comments may be shown as answers.
Smruti Ranjan
Top achievements
Rank 1
Smruti Ranjan asked on 11 Sep 2012, 02:03 PM
As per my requirement i need when the MinValue for a RadNumericTextBox is set to 0 it should not even allow to type the '-' character into the RadNumericTextBox.

It should behave in the same way as it behaves for any other characters, but now even the MinValue is set to 0 it allows to type the '-'/hyphen character. I am handling this situation by implementing the RangeValidation on the RadNumericTextBox so that it is showing the error message on focus out from it or on click of the 'Save' button.

Can anybody help me in this regard if there is a way to make it behave in the same way it behaves for other characters when entered like(do not allow user to type the character and show an error icon) ?

Hoping for a satisfactory option should be there. Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 14 Sep 2012, 08:08 AM
Hello Smruti Ranjan,

You can achieve this functionality by utilizing the KeyPress client side event and fire an error event when the required conditions are met:

Markup:

<telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox1" MinValue="0">
    <ClientEvents OnKeyPress="MyKeyPress" />
</telerik:RadNumericTextBox>

JS:

<script type="text/javascript">
    function MyKeyPress(sender,args)
    {
        if (sender.get_minValue() == 0 && args.get_keyCode() == 45)
        {
            sender.raise_error(new Telerik.Web.UI.InputErrorEventArgs(
                            "InvalidKeyPressed",
                            "-"));
            args.set_cancel(true);
        }
    }
</script>

I hope this helps.

Kind regards,
Martin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Smruti Ranjan
Top achievements
Rank 1
answered on 17 Sep 2012, 07:18 AM
Thanks Martin,

It is the exact what i was looking for... :)
Tags
Input
Asked by
Smruti Ranjan
Top achievements
Rank 1
Answers by
Martin
Telerik team
Smruti Ranjan
Top achievements
Rank 1
Share this question
or