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

RadNumericTextBox Allows Empty Strings

9 Answers 993 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ristogod
Top achievements
Rank 2
Ristogod asked on 11 Nov 2008, 05:16 PM
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?

9 Answers, 1 is accepted

Sort by
0
Ristogod
Top achievements
Rank 2
answered on 11 Nov 2008, 05:22 PM
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.
0
Ristogod
Top achievements
Rank 2
answered on 11 Nov 2008, 05:33 PM
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.


0
Accepted
Serrin
Top achievements
Rank 1
answered on 11 Nov 2008, 06:42 PM
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):

        double testNum = Convert.ToDouble(rnt1.Value);  
        if (testNum < rnt1.MinValue)  
            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...
0
Ristogod
Top achievements
Rank 2
answered on 11 Nov 2008, 07:23 PM
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.
0
Hiren Savjiyani
Top achievements
Rank 2
answered on 27 May 2009, 08:50 AM
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.
0
brian
Top achievements
Rank 1
answered on 20 Jun 2011, 05:57 PM
good question.  It seems this is still an issue.
0
Marin
Telerik team
answered on 23 Jun 2011, 12:37 PM
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.

0
Robert
Top achievements
Rank 1
answered on 09 Dec 2011, 09:12 PM
I am having similar issue... this seems like a perfect scenario for Telerik to step in and add a property:

ForceMinValueOnEmpty = True/False

0
Marin
Telerik team
answered on 12 Dec 2011, 12:11 PM
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
Tags
Input
Asked by
Ristogod
Top achievements
Rank 2
Answers by
Ristogod
Top achievements
Rank 2
Serrin
Top achievements
Rank 1
Hiren Savjiyani
Top achievements
Rank 2
brian
Top achievements
Rank 1
Marin
Telerik team
Robert
Top achievements
Rank 1
Share this question
or