Range validator controls enable you to check whether the value of form is between a minimum and maximum number or not.
It is will set the range when the user can input the value between limited numbers.
Range validator doesn’t give you the error when you didn’t put anything into the field. If you set it so, you must be set Required Field Validator.
If you didn’t use the required field validator and user didn’t write anything into the field so, It will be submit. No error can occurred.
You must set the five properties for range validator.-
- Control to validate- you must select a text box here.
- Text – You must write an error message.
- Minimum value- set the minimum value of validation range.
- Maximum value- set maximum value of validation range.
- Type- must set the data type.
Let’s see the practically range validator.
Firstly you need to install editor here I used visual studio 13
- Open your visual studio 13 and create a project
In previous program whatever you have to follow after that.
- Firstly write age.
- Form the tool box search textbox. Drag and drop that textbox.
- Drag and Drop a submit button.
4. Form toolbox search range validator. Drag and drop it after the text box.
5. Now we set the properties. firstly control to validate select text box that is use for range validation. Here I select textbox2 because I used it for range validator.
6. Secondly write a error message into the text properties. Here I write age between 12-20.
7. Change the color to set the ForeColor properties. Here I have to select red color. Red color used for showing the error message so, I have to used it. It is up to you whatever message and color you want to used.
8. Thirdly the most important properties for range validator. Set the maximum and minimum value. So, here I take 10 for the minimum value and 20 for the maximum value.
9. Fourthly, after sets the range of range validator it is the most important properties. Set the Datatype, here the type means datatype. I am using the age so, for that, I have to use the Integer as a datatype. meanwhile, you set the string, date, time, range, etc…
10. You must be write this code inside the web.config file. Inside the configuration tag.
<appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"></add> </appSettings>
11. After writing the above code you must be save the web.config file and closed it.
12. Go for your design and run your aspx file.
13. Congratulation You got the output.
14. In this output I have to enter the 1 so it will give me the error message “age between12-20“. This message I was set into the properties.
15. In this output I put 12 so it is in between my range “12-20“. So, it didn’t give the error.