Non-numeric value in RadNumericTextBox control

7 posts, 1 answers
  1. Ryan Kim
    Ryan Kim avatar
    4 posts
    Member since:
    Feb 2010

    Posted 25 Feb 2010 Link to this post

    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.
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 25 Feb 2010 Link to this post

    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?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ryan Kim
    Ryan Kim avatar
    4 posts
    Member since:
    Feb 2010

    Posted 25 Feb 2010 Link to this post

    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.
  5. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 26 Feb 2010 Link to this post

    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.
  6. Ryan Kim
    Ryan Kim avatar
    4 posts
    Member since:
    Feb 2010

    Posted 26 Feb 2010 Link to this post

    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?
  7. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 01 Mar 2010 Link to this post

    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.
  8. Ryan Kim
    Ryan Kim avatar
    4 posts
    Member since:
    Feb 2010

    Posted 01 Mar 2010 Link to this post

    Yeah, that's what I ended up doing. Thank you very much though.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017