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.
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.
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.
All of the validation controls derive from the Base Validator class, giving them common methods and properties.
Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange So I've chosen to write just one method (will be a static method of a 'validator' class) that can handle validation for both and am unsure if this is a good idea - having a method that essentially does I've run some tests to check the edge cases and passing in empty strings etc and it passed them, but for some reason this feels kind of wrong.
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.You should use two methods where each validates one type only.