<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

int myValue = (int)rntbLineNumber.DbValue; |
Which still throws an error saying that the object is a null reference.

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.

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...

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.


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.

ForceMinValueOnEmpty = True/False
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.
Marin
the Telerik team