There are four key properties to initialize for a Range Validator.The Control To Validate property references the ID of the input control to check.
Simply put, never trust the data in an incoming request, and always validate on the server.
When validation fails the normal flow of execution continues.
There are various validation controls availabe, and we will cover them in the rest of the article.
All of the validation controls derive from the Base Validator class, giving them common methods and properties.
We want to make sure a user enters a hire date, the date is in a valid format, and the data is within one week (plus or minus) of today’s date.
The code in our ASPX file should look like the following.
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.
Notice in the following screen capture, we can see the Required Field Validator error message display on the form. The user does not wait on a server round trip to discover errors.
Not executing server side validation leaves your application code vulnerable to malicious users.