C validating cancel button
Html Controls; namespace Web Data Validation When the user clicks the Cancel button we clear the Text Box control and allow the user to start over.
There are good reasons to always execute validation checks on the server.
We have seen the Required Field Validator in our first sample program, let’s move on to examine the rest of the controls.
The Range Validator control ensures the value inside a control is within a specified range.
If the conversion fails, the validation also fails.
To demonstrate the Range Validator, we will add an additional Text Box control to our web form (Hire Date Text Box), and a Range Validator.
As we mentioned earlier, validation controls execute when the user clicks a Button control, including HTML button controls and server button controls such as the Link Button and Image Button.
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.
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.
The associated control is set by right clicking on the validator and selecting Properties from the context menu. The rest of the validation controls provided by ASP.
In the Properties dialog box find the Control To Validate property and select First Name Text Box from the drop down list. We can set other properties, such as the Error Message property, and the final ASPX source code should look like the following. NET work in a similar fashion to what we've seen above. If the client's web browser is of executing client side Java Script, the first validation pass occurs on the client.
There are various validation controls availabe, and we will cover them in the rest of the article.