Validating data in asp
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.All of the validation controls must have the Control To Validate property set before rendering the page or the control throws an exception.The cancel button has a Causes Validation property. As we mentioned in the beginning of the article, validation can occur twice: once on the client’s machine and once on the server. Client side validation provides quick feedback for the user.Validation occurs when a user clicks any Button control by default, but you can change this behavior by setting the Causes Validation property to false. Whenever the user presses a button on the form, the script executes the validation checks for each validation control on the form.Drag one Text Box control and give it an ID of First Name Text Box, two Button controls (Submit Button and Cancel Button), and one Required Field Validator (First Name Required Field Validator). The following screen shows the form in action, and the user has pressed the Submit button without entering any text into the textbox. The Required Field Validator fails when the value in the associated control matches the value of the Initial Value property of the Required Field Validator.This Required Field Validator forces the user to enter text into the control associated with the validator. If you want to make sure the user changes a default value placed into the control, set the control’s Text value and the Initial Value property of the Required Field Validator to the same value.We have seen the Required Field Validator in our first sample program, let’s move on to examine the rest of the controls.
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 one exclusion to this rule is the Custom Validator component.
You can validate the following server controls: Text Box, List Box, Drop Down List, Radio Button List, and the following HTML controls: Html Input Text, Html Input File, Html Select, and Html Text Area.
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.