RadNumericTextBox Allows Empty Strings

10 posts, 1 answers
  1. Ristogod
    Ristogod avatar
    63 posts
    Member since:
    Aug 2008

    Posted 11 Nov 2008 Link to this post

    I'm using a RadNumericTextBox like shown below:

     
                <telerik:RadNumericTextBox  
                    ID="rntbLineNumber"  
                    MinValue="1" 
                    MaxValue="32767" 
                    Type="Number" 
                    runat="server"
                    <NumberFormat DecimalDigits="0" GroupSeparator="" /> 
                </telerik:RadNumericTextBox>


    The goal is to insure that the value entered is always between 1 and 32767. However, it allows me to enter an empty string which causes this line to fail on posting.

     int myValue = int.Parse(rntbLineNumber.Text); 

    I'm guessing that I'm supposed to get the value from another property other than "Text" off of the RadNumericTextBox. However, I still feel that the control should be enforcing my input constraints, where a specify a valid range, client-side. In other words, an empty string should populate the field with the minimum value. Is there anyway to do this? Or do I simply have to allow empty strings to be posted?
  2. Ristogod
    Ristogod avatar
    63 posts
    Member since:
    Aug 2008

    Posted 11 Nov 2008 Link to this post

    I tried using the DBValue property instead like so

    int myValue = (int)rntbLineNumber.DbValue;  

    Which still throws an error saying that the object is a null reference.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ristogod
    Ristogod avatar
    63 posts
    Member since:
    Aug 2008

    Posted 11 Nov 2008 Link to this post

    int myValue = Convert.ToInt32(rntbLineNumber.Value); 

    And using this gives me the value zero, which is incorrect as it is outside of the acceptable range.


  5. Answer
    Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 11 Nov 2008 Link to this post

    Hey Ristogod,

    Well, two options you have are to use either a validator on the input box or work up javascript validation, but since it looks like you're using some code behind, you could try this (using double type because MinValue is stored as a double):

    1         double testNum = Convert.ToDouble(rnt1.Value);  
    2         if (testNum < rnt1.MinValue)  
    3             testNum = rnt1.MinValue; 

    Quick and easy way to grab value and check it against your min value.  Tested it with pasting spaces, an M, etc...
  6. Ristogod
    Ristogod avatar
    63 posts
    Member since:
    Aug 2008

    Posted 11 Nov 2008 Link to this post

    That's a pretty good fix. Unfortunately for me, that won't probably won't work for what I need to do. On the flip-side, our application has some validation that essentially returns a violation for any value set outside of the desired range. So the message they see is that the value cannot be less than 1. Which some what makes enough sense that an empty field could be interpreted as less than 1.

    I'm going to mark your post as the correct answer. I feel despite not being ideal for me, it would most likely be ideal enough for 99% of everyone else that may run into this scenario. Thanks for your help Serrin.
  7. Hiren Savjiyani
    Hiren Savjiyani avatar
    13 posts
    Member since:
    May 2008

    Posted 27 May 2009 Link to this post

    In radnumerictexbox why its allowed empty string i don't know we set min value after that still allows me to enter blank value is there any easy validation except put asp.net validation control or javascript.
  8. brian
    brian avatar
    36 posts
    Member since:
    Jul 2010

    Posted 20 Jun 2011 Link to this post

    good question.  It seems this is still an issue.
  9. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 23 Jun 2011 Link to this post

    Hi Brian,

     Specifying min and max values does not make the control a required field. It only validates whether any entered value is within the specified range. Also in the latest version the control does not allow other input than digits. If you need to make the textbox a required field you can use some custom validators or javascript.

    Regards,
    Marin
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  10. Robert
    Robert avatar
    198 posts
    Member since:
    Aug 2009

    Posted 09 Dec 2011 Link to this post

    I am having similar issue... this seems like a perfect scenario for Telerik to step in and add a property:

    ForceMinValueOnEmpty = True/False

  11. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 12 Dec 2011 Link to this post

    Hello Robert,

     Thank you for the suggestion. We will consider adding such feature based on popular demand.
    For now you can use the RadInputManager which allows you to add both numeric and required field validation settings to a regular textbox.

    Greetings,
    Marin
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017