Frequently Asked Interview Questions

ASP.NET Validation Controls FAQS

ASP.NET Validation Controls FAQS page 1
Asp.Net validation controls are used to validate user input based on validation criteria. Validation controls can be used to address the following questions.
  • Did user enter value for required field? 
  • Is the entered input is appropriate kind of data?
  • Is the data within required range?
The validation controls check the validity of data entered in associated server controls on the client before the page is posted back to the server.
ASP.NET validation controls validate data first on the client and then on the web server. If a client disables javascript on the browser then, client side validations are bypassed and validations are performed on the web server.
ASP.NET Validations Controls are 
  1. RequiredFieldValidator :- Checks whether a control contains data.
  2. CompareValidator :- Checks whether an entered item value matches an entry in another control.
  3. RangeValidator :- Checks whether an entered values is in specified range.
  4. RegularExpressionValidator :- Checks whether an entered item matches a specified format. 
  5. CustomValidator :- Checks the validity of an entered item using a client-side script or a server-side code, or both.
  6. Validation Summary :- Displays validation errors in a central location or display a general validation error description.
  1. ControlToValidate:- The ID of the control for which the user must provide a value.
  2. ErrorMessage:- Error Message to be displayed if validation fails (Ex: First name is required)
  3. Display :- display mode can be None/Static/Dynamic 
    • None : Validation message is never displayed 
    • Static: Space for the validation message is allocated in the page layout 
    • Dynamic: Space for the validation message is dynamically added to the page if validation fails. 
  4. Text :-  * A star is a conventional way of indicating that a field is required. This text will be displayed only if there is an error 
  5. ValidationGroup:- We can group validators into groups that are treated as a unit.
No, validation controls are not fired on the client side if javascript is disabled on the client browser.
By Setting CauseValidation button property to false
Let us assume we have a Page that collects user information like name, age, date of birth, gender with a submit and reset buttons. When I click the submit button the information filled on the form should be validated and saved to the database. If I click the reset button then all the controls on the webform should default to their initial values without validation happening.So you have to set the CausesValidation property of the reset button to false for the validation to be bypassed. Other wise you will not be able to post back the page to the server.
ASP.NET Custom Validator is used to perform complex types of validation not provided by the standard validation control, use a CustomValidator control and write code to perform the validation on the server side and optionally on the client side.
We use Page.IsValid property to determine if all the validations have succeeded. For this property to return true, all validation server controls in the current validation group must validate successfully.
Call Page.Validate() method. When this method is invoked, it iterates through the validation controls contained in the ValidatorCollection object associated with the Page.Validators property and invokes the validation logic for each validation control in the current validation group.

Most Visited Pages

Home | Site Index | Contact Us