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

3 posts, 1 answers
  1. Smruti Ranjan
    Smruti Ranjan avatar
    22 posts
    Member since:
    Feb 2012

    Posted 11 Sep 2012 Link to this post

    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. Answer
    Martin
    Admin
    Martin avatar
    811 posts

    Posted 14 Sep 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Smruti Ranjan
    Smruti Ranjan avatar
    22 posts
    Member since:
    Feb 2012

    Posted 17 Sep 2012 Link to this post

    Thanks Martin,

    It is the exact what i was looking for... :)
Back to Top