RadNumericTextBox to accept only postive integers

19 posts, 0 answers
  1. Mark
    Mark avatar
    97 posts
    Member since:
    Nov 2007

    Posted 09 Mar 2008 Link to this post

    Hi

    Is there a way for the RadNumericTextBox to accept only postive integers?

    I.e:

    • No negatives
    • No decimals
    • No group formatting

    I don't know if this is the right approach but for the decimal separator I used "©".

    The database stores a 10 digit positive integer.


    Kind regards

    Mark Eaton

  2. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 10 Mar 2008 Link to this post

    hi:)

    You can use MinValue property

    Here is an example:

                <telerik:RadNumericTextBox   
                    MinValue="0"   
                    MaxValue="999999999"   
                    ID="RadNumericTextBox1"   
                    runat="server">  
                    <NumberFormat GroupSeparator="" DecimalDigits="0" /> 
                </telerik:RadNumericTextBox> 


    Regards...
    <John:Peel />
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark
    Mark avatar
    97 posts
    Member since:
    Nov 2007

    Posted 10 Mar 2008 Link to this post

    Hi John

    Thanks for your quick reply and code example. It worked first time!


    Kind regards

    Mark Eaton
  5. Mark DeMichele
    Mark DeMichele avatar
    74 posts
    Member since:
    Oct 2005

    Posted 20 Nov 2008 Link to this post

    Hi there,

    This solution works almost perfectly, but the user is still permitted to type in a decimal point. Is there any way to reject the decimal point altogether, i.e., have the same effect as if the user typed in a letter?

    I can achieve something close to what I need by using the following, but in my case it doesn't make sense to allow the decimal point at all.

         <telerik:RadNumericTextBox    
                    MinValue="0"    
                    MaxValue="999999999"    
                    ID="RadNumericTextBox1"     
                    runat="server">   
                    <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true"   KeepNotRoundedValue="false"  />  
                     
                </telerik:RadNumericTextBox>  


    Mark
  6. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 20 Nov 2008 Link to this post

    Hi Mark,

    The following code example demonstrates how to reject the decimal separator:

        <div> 
            <script type="text/jscript"
                function KeyPress(sender, args) { 
                    if (args.get_keyCharacter() == sender.get_numberFormat().DecimalSeparator) { 
                        args.set_cancel(true); 
                    } 
                } 
            </script> 
            <telerik:RadNumericTextBox     
                MinValue="0"     
                MaxValue="999999999"     
                ID="RadNumericTextBox1"      
                runat="server">    
                <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true"   KeepNotRoundedValue="false"  />   
                <ClientEvents OnKeyPress="KeyPress" />                  
            </telerik:RadNumericTextBox>   
        </div> 



    Greetings,
    Plamen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Mark DeMichele
    Mark DeMichele avatar
    74 posts
    Member since:
    Oct 2005

    Posted 20 Nov 2008 Link to this post

    Thanks for the quick reply and work-around. 

    That being said, I would just like to give you my oppinion on something.  In a lot of cases, the RadControls save me a lot of work so I can't really complain.  You have a good product and I appreciate your hard work and good support.  Your technical support response time is faster than any other vendor I know.

    However, sometimes for such simple features you have to jump through hoops to get it to do trival things, this feature in particular, in my oppinion should have been built in in the first place.  I have a large site with many pages and many input fields.  It would have been really nice to not have to add the same javascript snippet on each and every page.  Plus, in cases where I actually need the KeyPress for something else, it really complicates things.

    At some point, I think you need to compile a list of "features" that could easily be automated and implement those.  Giving the programmer and simple "drop-in" control (with no extra codiing) should be the highest priority.  A simple property that told the box it was an integer would have been perfect.  Maybe you can consider it for a future release.

    Thanks again for your product.  I think it's great and you guys are doing a great job.
  8. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 21 Nov 2008 Link to this post

    Hi Mark,


    Thank you for the nice words - we are happy to hear that you like our products

    We are always open for new ideas and suggestions and our new features are based on customer feedback. Keep sharing your suggestions, as it will not remain overlooked. Our main goal is to continue improving our products and make them more attractive to the clients.

    Sincerely yours,
    Plamen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Shark75
    Shark75 avatar
    32 posts
    Member since:
    Apr 2007

    Posted 12 Mar 2009 Link to this post

    We have receieved a bug report with this exact problem where the user is allowed to type decimal points and minus symbols, whilst submitting the value is rejected by the range validation (MinValue, MaxValue).

    Sorry, I haven't tried the fix suggested here, but I don't see that working for copying/pasting a value with decimal points or minus symbols in as it only handles key presses (copy and paste can be achieved with the mouse alone).

    Is there a solution to both scenarios?

  10. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 16 Mar 2009 Link to this post

    Hi Simon,

    The suggested approach should work for you when you set the MinValue and DecimalDigits properties as shown. When pasting into the control, it is parsing the number according to these properties and thus will not display a negative value or a decimal separator at all.

    Sincerely yours,
    Pavel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. Shark75
    Shark75 avatar
    32 posts
    Member since:
    Apr 2007

    Posted 17 Mar 2009 Link to this post

    It doesn't remove the negative symbol or decimal separator when you copy a negative number with a decimal place in it from another application and paste into the RadNumericTextBox using the content menu paste function (mouse only)...

    1) Open notepad and type in -0.1.
    2) Copy -0.1 into your clipboard using CTRL+C or whatever method you normally use.
    3) Right click on the RadNumerictextBox and select the Paste option.
    4) Because this isn't happening from a key press it accepts it, flashes the invalid styling at you, but leaves it there still.

    P.S. I'm using ASP.Net Rad Controls myself (the non-ajax version), so I had to change the keypress function to check args.KeyCode and a hard coded value as you can't get at the number format stuff client side in the non-ajax version, but I've tried both it and the new Ajax version and they both suffer the same problem that this is only reacting to key presses not mouse events.
  12. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 18 Mar 2009 Link to this post

    Hello Simon,

    This scenario should be handled by the control itself regardless whether the custom javascript function is applied. The value will be changed when the control loses focus. Note that I just tested this with the classic version of the control as well and it behaves the same way. I am attaching a video for illustration. Take a look at it and let me know if I am missing something.

    Best wishes,
    Pavel
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  13. Shark75
    Shark75 avatar
    32 posts
    Member since:
    Apr 2007

    Posted 18 Mar 2009 Link to this post

    Hi Pavel,

    Thanks for the video.

    Yes you're correct the RadNumericTextBox when it has Min and Max values on it does reset the value when you lose focus (dunno what I've done differently now to get the same behaviour as you, user error! :-)). Wierdly though in my sample application the ASP.NET AJAX version (Prometheus) doesn't reset the value, it leaves the invalid value in. What am I missing?

    Sample video

    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"
        <title></title
        <script type="text/javascript"
            function KeyPress(sender, args) 
            { 
                if (args.KeyCode == 45 || args.KeyCode == 46)  
                { 
                    return false; 
                } 
            } 
            function NewKeyPress(sender, args)  
            { 
                var keyCharacter = args.get_keyCharacter(); 
                 
                if (keyCharacter == sender.get_numberFormat().DecimalSeparator || 
                    keyCharacter == sender.get_numberFormat().NegativeSign)  
                { 
                    args.set_cancel(true); 
                } 
            }  
        </script>  
    </head> 
    <body> 
        <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <div> 
            <span>RadNumericTextBox:</span> 
            <rad:RadNumericTextBox ID="RadNumericTextBox1" runat="server"    
                MinValue="1" MaxValue="999999999" >     
                <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false"  />    
                <ClientEvents OnKeyPress="KeyPress" />                   
            </rad:RadNumericTextBox>    
            <br /><br /> 
            <span>ASP.NET AJAX RadNumericTextBox:</span> 
            <telerik:RadNumericTextBox ID="RadNumericTextBox2" runat="server" 
                MinValue="1" MaxValue="999999999" >     
                <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false"  />    
                <ClientEvents OnKeyPress="NewKeyPress" />                   
            </telerik:RadNumericTextBox>    
        </div> 
        </form> 
    </body> 
    </html> 
     

    P.S. What do you use to capture the video, I've been using CamStudio, which is ok, but a bit clumsy?
  14. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 19 Mar 2009 Link to this post

    Hello Simon,

    The problem when using this markup is caused by a bug in the Asp.Net AJAX version of the control. When used on the same page with the classic version of RadInput the control seems to be using the wrong scripts, so it is generating javascript errors. I have notified our developers about this and they will look into it. I have also updated your telerik points for bringing it to our attention. Note that if you use only the new controls you should not experience this problem.

    As for the video recording, I use SnagIt which is easy to use and pretty much covers everything you might need.

    I hope this helps.

    Best wishes,
    Pavel
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  15. Mateusz
    Mateusz avatar
    14 posts
    Member since:
    Aug 2012

    Posted 06 Dec 2012 Link to this post

    MinValue="0"
    MaxValue="999999999"
    ID="RadNumericTextBox1"
    runat="server">
    <NumberFormat GroupSeparator="" DecimalDigits="0" />
    </telerik:RadNumericTextBox>

    i use this and i can still type in negative values :(
  16. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2012 Link to this post

    Hi,

    Try the following code snippet to cancel the negative values in the RadNumericTextBox.

    ASPX:
    <telerik:RadNumericTextBox MinValue="0" MaxValue="999999999" ID="RadNumericTextBox1"
        runat="server">
        <NumberFormat GroupSeparator="" DecimalDigits="0" />
        <ClientEvents OnKeyPress="NewKeyPress" />
    </telerik:RadNumericTextBox>

    JS:
    <script type="text/javascript">
        function NewKeyPress(sender, args) {
            var keyCharacter = args.get_keyCharacter();
            if (keyCharacter == sender.get_numberFormat().NegativeSign) {
                args.set_cancel(true);
            }
        
    </script>

    Hope this helps.

    Regards,
    Princy.
  17. Jean-Christian
    Jean-Christian avatar
    1 posts
    Member since:
    Jan 2014

    Posted 10 Nov 2015 in reply to Plamen Peshev Link to this post

    Hi,

    I have the same problem as Mark. Indeed, user can type the decimal separator even if the decimaldigits is set to 0.

    in 2008, you proposed to insert a little javascript code in the page. But, as for Mark, it is difficult for me to insert a lot of little javascript code blocs everywhere in my pages. Moreover, if I need to change the backcolor of a radnumerictextbox, Telerik poroposes to add a little javascript, if I want to hide a radcalandar when the focus goes to another control, Telerik proposes to insert a little javascript, and so on... At the end, I need to add and maintain a lot of little javascript code blocs in my pages and it becomes really boring.

    In 2015, is there a way to prevent the user from typing a decimal separator without having to add a "little javascript".

    Regards,

     

  18. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 13 Nov 2015 Link to this post

    Hi Jean-Christian,

    Unfortunately the required functionality is still not added to the NumericTextBox control and you should add custom client code to achieve the required functionality.


    Regards,
    Maria Ilieva
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  19. Pierre
    Pierre avatar
    56 posts
    Member since:
    Jun 2016

    Posted 27 Sep Link to this post

    Hi,

    It's 2016, Is the functionality  added to the NumericTextBox control ?
    We had 4 major release since last time  some one ask for it.

     
  20. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 30 Sep Link to this post

    Hi Pierre,

    At the moment, the required functionality can only be achieved by using custom client code for canceling the negative values.

    Excuse us for any inconvenience this issue may lead.


    Regards,
    Maria Ilieva
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017