I have a pretty simple ASP.NET page with some input fields and validators. One field accepting a double looks like this:
<asp:TextBox ID="tbHeight" runat="server" />
<asp:RangeValidator ID="vdHeight" runat="server"
ErrorMessage="Height must be a positive number" Text="*"
ControlToValidate="tbHeight" MinimumValue="0" Type="Double" />
This works as expected, and the user must enter a number >= 0.
Update: this does not work as expected afterall (some weird bug in the project). See comments to the answers below for details
I then try the same for a field accepting an integer:
<asp:TextBox ID="tbGrossTonnage" runat="server" />
<asp:RangeValidator ID="vdGrossTonnage" runat="server"
ErrorMessage="Gross Tonnage must be a positive whole number" Text="*"
ControlToValidate="tbGrossTonnage" MinimumValue="0" Type="Integer" />
When loading the ASP-page, this gives me the following error: The value '' of the MaximumValue property of 'vdGrossTonnage' cannot be converted to type 'Integer'.
I don't have any specific max value requirements in the system, so I would just like it to "default" to Int32.MaxValue
(although I'd have to enter 2,147,483,647, since MaximumValue
doesn't seem to accept the Int32.MaxValue
constant).
Why is it that a RangeValidator
of the type Integer
won't accept a missing MaximumValue
property, but for one of the type Double
this is ok?