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

Issues with smaller value types than Int32

6 Answers 56 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Schalk
Top achievements
Rank 1
Schalk asked on 28 Mar 2011, 11:12 AM
Good day,
I noticed there's an issue with NumericTextBox regarding smaller value types than Int, I reviewed the telerik source from codeplex and made a few small changes, but essentially the following code fixes the problem:

TValue defaultT = default(TValue);
Type targetType = typeof(TValue);
MinValue = (TValue)targetType.GetField("MinValue").GetValue(defaultT);
MaxValue = (TValue)targetType.GetField("MaxValue").GetValue(defaultT);
 
IncrementStep = (TValue)Convert.ChangeType(1, targetType);

The main issue on the NumericTextBox is that it sets the default MaxValue to Int32.MaxValue, which generates an error when the generic type is something like byte or short, but also produces a logical problem if the type is double or long considering the max value of Int32 is much smaller than the aforementioned.

I also used the same code from above to change the IntegerTextBox to have similiar functionality such as the NumericTextBox in regards to using generic parameters using the same code and making changes (effectively, all of the code for IntegerTextBox ended up almost identical to the NumericTextBox with only the DecimalDigits value being default to 0).

Of coarse error check would be somewhat necessary, but in our case not so much required.

Hope to see this change in Telerik MVC Extensions code as well soon, will be using my custom build so long :)

6 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 28 Mar 2011, 12:05 PM
Hello Schalk,

Thank you for contacting us. 

This is known issue which is already fixed. The fix will be included in the next official release of the Telerik components for ASP.NET MVC.

Regards,
Georgi Krustev
the Telerik team
0
Schalk
Top achievements
Rank 1
answered on 28 Mar 2011, 05:57 PM
Thanks for the prompt reply Georgi Krustev,
any chance in the next release that the IntegerTextBox will also accept generic parameters instead of defaulting to type Int32?
0
Atanas Korchev
Telerik team
answered on 29 Mar 2011, 07:40 AM
Hello Schalk,

 No, this will not be implemented in the next official release. I will log it as a feature request and it will be considered evaluated by the product team.

Regards,
Atanas Korchev
the Telerik team
0
Kenneth
Top achievements
Rank 1
answered on 02 Nov 2012, 05:28 PM
Any update on this?  As of MVC Extensions 2012.2.607, IntegerTextBoxFor still blows up when used on an Int16 property.  I get this error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

0
Georgi Krustev
Telerik team
answered on 06 Nov 2012, 11:20 AM
Hello Kenneth,

 
This functionality is still under consideration. I will suggest you use a NumericTextBox<Int16> and specify the DecimalDigits to 0:

Html.Telerik().NumericTextBox<Int16>()
         .Name("...")
         .DecimalDigits(0) // IntegerTextBox makes this internally.
Thus you will get component which accepts Int16 and does not allow fractions.

Regards,
Georgi Krustev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Kenneth
Top achievements
Rank 1
answered on 06 Nov 2012, 03:22 PM
Thanks!  A simple, and obvious fix.  I should have figured that out on my own via API exploration -- lazy of me!  =)
Tags
NumericTextBox
Asked by
Schalk
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Schalk
Top achievements
Rank 1
Atanas Korchev
Telerik team
Kenneth
Top achievements
Rank 1
Share this question
or