Don't allow negative value in RadNumericTextBox

2 posts, 0 answers
  1. Nileshkumar
    Nileshkumar avatar
    18 posts
    Member since:
    May 2011

    Posted 09 Jul 2013 Link to this post

    Hi,
    I have widely used RadNumericTextBox in my application. I want to restrict the user to enter negative value in the RadNumericTextBox without set to MinValue = 0. We can set MinValue=0 but in this case also user can enter the negative value however it will be set to 0 by default.
    But i don't want to allow the user to enter negative values in entire application. Can anyone have solution to solve this issue ?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Jul 2013 Link to this post

    Hi Nileshkumar,

    If you want to restrict the user from entering the minus (-) character into the RadNumericTextBox, try attaching the following JavaScript code to the OnKeyPress Client event of the control.

    JavaScript:
    <script type="text/javascript">
        function keypress(sender, args) {
            if ((args.get_keyCode() == 109) || (args.get_keyCode() == 45)) {
                args.set_cancel(true);
            }
        }
    </script>

    Thanks,
    Princy.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top