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

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

1 Answer 128 Views
Input
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 24 Jan 2015, 04:01 PM
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"/>
</telerik:RadNumericTextBox>

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?  

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 28 Jan 2015, 01:29 PM
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"
    MaxLength="14"
    Width="250px"
    Type="Currency"
    AutoPostBack="true"
    Enabled="true"
    AllowOutOfRangeAutoCorrect="false">
    <NumberFormat DecimalDigits="2"
        KeepNotRoundedValue="False" />
</telerik:RadNumericTextBox>
<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.



Regards,
Viktor Tachev
Telerik
 

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.

 
Tags
Input
Asked by
Matt
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or