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

Non-numeric value in RadNumericTextBox control

6 Answers 172 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ryan Kim
Top achievements
Rank 1
Ryan Kim asked on 25 Feb 2010, 06:22 PM
Hi,

I will explain what behavior I want and would like to know if that is possible or if there is any workaround.

I have a RadNumericTextBox control called txtNumber created. But from the backend-code, I'd like to feed any type of variable(string, double, int) instead of just numeric types and still be able to display the string value in the textbox. But from the UI, user should only be able to type numbers and as user loses focus from the textbox, number inside the textbox should do the reformatting (putting thousand separators and decimal points, etc. like regular RadNumericTextBox). Is there a way I can do this? or is there a way I can use other types of textbox so it can have string value but limit user inputs to numeric types and do the reformatting?

Thank you very much in advance.

6 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 25 Feb 2010, 07:49 PM
If you questions is about not having to convert a string/double/int variable when setting the RadNumericTextbox value, you can always use the DbValue property to set the value and the RadNumericTextbox will take care of the conversion process.

Is that what you're asking?
0
Ryan Kim
Top achievements
Rank 1
answered on 25 Feb 2010, 08:05 PM
Not really :(

I'm pulling values from a database table where the column's data type is varchar. I set it up that way so the column can store both numeric type and non-numeric type. What I'm asking is that I'd still like to display the value I get from the database table even if it's not a numeric type. eg. ) Value_From_Database = "AAA";   I'd still like to display "AAA" in the textbox but when user tries to make changes, it will only allow typing numbers and will throw error if non-numeric characters are not removed.
0
robertw102
Top achievements
Rank 1
answered on 26 Feb 2010, 02:44 PM
Maybe you could use a normal asp:TextBox control and then use the RadInputManager control to set a NumericSetting on that textbox and set it to validate the input to prevent non-numeric data from being saved. I guess that might work for your situation.
0
Ryan Kim
Top achievements
Rank 1
answered on 26 Feb 2010, 03:54 PM
Thank you for the response.

<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> 
 
    <telerik:RadInputManager ID="RadInputManagerStatement" runat="server"
        <telerik:NumericTextBoxSetting BehaviorID="NumericBehavior1" Validation-IsRequired="true"
            <TargetControls> 
                <telerik:TargetInput ControlID="TextBox4" /> 
            </TargetControls> 
        </telerik:NumericTextBoxSetting> 
    </telerik:RadInputManager>     
 

This works fine when I set TextBox4.Text = "5.25"; from the code-behind and everything works as expected from the page. But it does not show anything in the textbox when I set TextBox4.Text = "A"; What should I do?
0
Accepted
Veli
Telerik team
answered on 01 Mar 2010, 04:32 PM
Hi,

Unfortunately, you cannot do this automatically neither with RadNumericTextBox, nor with the NumericTextBoxSetting  of the RadInputManager. If you try to set a non-numeric string to RadNumericTextBox, it will complain with an exception. If you try to set the same string to a TextBox that is controlled by RadInputManager, you will not get the string in the textbox.

So, there is no silver bullet for this case. If you choose to be able to enter custom text on the server, you will have to use TextBox or RadTextBox and write your own validation logic to validate numeric user input.

Regards,
Veli
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Ryan Kim
Top achievements
Rank 1
answered on 01 Mar 2010, 04:51 PM
Yeah, that's what I ended up doing. Thank you very much though.
Tags
Input
Asked by
Ryan Kim
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Ryan Kim
Top achievements
Rank 1
Veli
Telerik team
Share this question
or