Range validator to validate percentage value
I want to use RangeValidator
to validate percentage value. For that I set minimum value as 0.0 and maximum value to 100.00, but i开发者_Python百科ts not working. I tried using minimum value as 0% and maximum values as 100% but still not working.
Here is some code:
<asp:RangeValidator ID="percentageRangeValidator" runat="server"
ControlToValidate="percentageBox" Display="Dynamic"
ErrorMessage="Invalid Percentage"
MaximumValue="100.00" MinimumValue="0.00">*</asp:RangeValidator>
What's wrong in my method.
You need to specify the type of the value Type="Double"
:
<asp:RangeValidator ID="percentageRangeValidator" runat="server"
ControlToValidate="percentageBox" Display="Dynamic"
ErrorMessage="Invalid Percentage" MaximumValue="100.00" MinimumValue="0.00"
Type="Double">*</asp:RangeValidator>
Can you try this code which includes "Type=Double" in Range Validator control
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox1" Type="Double" ErrorMessage="enter value bet ween 0 and 100"
MaximumValue="100.00" MinimumValue="0.00"></asp:RangeValidator>
You miss type attribute in you code. I am sending you an example code for this....
<asp:TextBox ID="txt" runat="server" />
<asp:RangeValidator ID="rng1" runat="server" ControlToValidate="txt" Display="Dynamic"
ErrorMessage="Invalid Percentage" SetFocusOnError="true" Text="Invalid Percentage"
ValidationGroup="check" MinimumValue="0.00" MaximumValue="100" Type="Double" />
<asp:Button ID="btn" runat="server" ValidationGroup="check" Text="Submit" />
精彩评论