The RangeValidator Server Control makes sure that the entered user value or selection provided is between a specified ranges.It is possible to check ranges within numbers, dates, and characters.
The validation will not fail if the input control is empty. Use the RequiredFieldValidator control to make the field required.
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="RangeValidator">
</asp:RangeValidator>
Properties:
ControlToValidate | The id of the control to validate |
Error Message | The text to display in the page when validation fails |
Maximum Value | Specifies the maximum value of the input control |
Minimum Value | Specifies the minimum value of the input control |
Type | Specifies the data type of the value to check. The types are: <![if !supportLists]> · <![endif]>Currency <![if !supportLists]> · <![endif]>Date <![if !supportLists]> · <![endif]>Double <![if !supportLists]> · <![endif]>Integer <![if !supportLists]> · <![endif]>String |
Code:
<asp:Label ID="Label1" runat="server" Text="NO OF Item"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="range should be between 5 to 10"
MaximumValue="10" MinimumValue="5" SetFocusOnError="True" Type="Integer">
</asp:RangeValidator>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="SUBMIT" />
When we will not enter value in the specified range then error message will show
When we enter the value in the specified range then page will execute
Leave Comment