RadNumericTextBox - How to check control for invalid state in code-behind

2 posts, 0 answers
  1. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 24 Jan 2015 Link to this post

    I have a RadNumericTextBox defined as follows:

    <telerik:RadNumericTextBox ID="txtMaxCost" Runat="server" MaxLength="14" Width="250px"  Type="Currency" SkinID="OverrideRadDefaultSkinWithNonExistantSkin" AutoPostBack="true" Enabled="true" AllowOutOfRangeAutoCorrect="false">
    <NumberFormat DecimalDigits="2" KeepNotRoundedValue="False"/>

    When users enter a number that's out of range (e.g., 77777777777777), the text turns red and a yield sign appears in the control when focus is lost.  When the user saves the object, the control's value is set to null and therefore, our validation isn't executed on the code-behind.

    I checked out the properties of the control and see there's an .Invalid property, but when I check it's state in the code, it's set to false.

    How can I check to see that the control is in an invalid state programmatically?  
  2. Viktor Tachev
    Viktor Tachev avatar
    2187 posts

    Posted 28 Jan 2015 Link to this post

    Hello Matt,

    When an invalid value is entered in RadNumericTextBox it is not submitted to the server. If you need to submit the value in the RadNumericTextBox control only when it is valid you can use RequiredFieldValidator control.

    The following markup illustrates the approach:

    <telerik:RadNumericTextBox ID="txtMaxCost" runat="server"
        <NumberFormat DecimalDigits="2"
            KeepNotRoundedValue="False" />
    <asp:RequiredFieldValidator ErrorMessage="error" ControlToValidate="txtMaxCost" runat="server" />

    On a side note, have in mind that RadNumericTextBox supports values that are between - 2^46 and + 2^46. In case a value outside that range is entered it may cause unexpected behavior.

    In case you would like additional information on the features of RadNumericTextBox you would find the following article interesting.

    Viktor Tachev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top