The Minimum Value and Maximum Value properties control the allowed range of the input. This property can take one of the following values: String, Integer, Double, Date, or Currency.The Range Validator will first try to convert the values it is examining into the type specified.As we will see later in the code-behind file, the Cancel Button will clear all of the fields on the form, and we do not want to validate any of the fields when the user presses this button. If any one of the validation controls on a form fails, the script cancels the postback operation and displays error messages on the form.
This is the exact position the error message will appear if validation fails. This also improves response time on the server because the ASP.
For this first example we do not need to place much code into the code-behind file. NET runtime does not waste time processing a request with invalid information.
We can double click on both of the Button controls on the form to add event handlers for the click events. If you want to disable just client side validation for a specific validation control, you can set the control’s Enable Client Script property to false. NET will always execute validation checks on the server when a button click event arrives requiring validation.
The complete listing for Web Form1cs is shown below. You can disable any of the validation controls by setting the Enabled property to false.
You need to check the Is Valid property to know if a validation check failed.
Validation is complete by the time you reach a click event.
Before accepting data from over the network you need to ensure all of the required fields have been filled out and conform to your formats and business rules. NET provides a number of validation controls to ease the burden of performing validation on both sides of the network. To walk along with the example, create a new web application in Visual Studio . Once the application is setup, right click on the empty web form, select Properties from the context menu, and change the Page Layout property to Flow Layout. Notice we need to check the Is Valid property of the base class before performing any critical action in the submit event.
Place four controls from the Web forms section of the Toolbox onto the form. If Is Valid returns a value of true then all of the validation checks were successful.
There are various validation controls availabe, and we will cover them in the rest of the article.