What is Validation control?
Let us assume we have a Page that collects user information like firstName, lastName age, date of birth, gender with a submit and reset buttons. When I click the submit button the information filled in 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 we have to set the CausesValidation property of the reset button to false for the validation to be bypassed. Otherwise, we will not be able to post back the page to the server.
What is ASP.NET Custom Validator used for?
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.
How do you programmatically check, if the client-side validation is not bypassed by disabling the javascript on the client browser?
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.
How do you programmatically invoke all validation controls on a page?
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.
What is a validation group?
Validation groups allow us to group validation controls on a page as a set. Each validation group can perform validation independently from other validation groups on the page.
How do you create a validation group?
We create a validation group by setting the ValidationGroup property to the same name for all the controls we want to group. We can assign any name to a validation group, but we must use the same name for all members of the group.
Explain how a validation group works when the Page is posted by clicking a button?
During postback, the Page class's IsValid property is set based only on the validation controls in the current validation group. The current validation group is determined by the control that caused validation to occur. For example, if a button control with a validation group of LoginGroup is clicked, then the IsValid property will return true if all validation controls whose ValidationGroup property is set to LoginGroup are valid.
Can a DropDownList fire validation controls?
Yes, DropDownList control can also fire validation if the control's CausesValidation property is set to true and the AutoPostBack property is set to true.
How do you programmatically force all validation controls in a particular validation group to be fired?
Call the Page.Validate(string GroupName) method and pass the name of the validation group. This will fire only the validation controls in that validation group.
What is SetFocusOnError property of a validation control used for?
Use the SetFocusOnError property to specify whether the focus is automatically set to the control specified by the ControlToValidate property when this validation control fails. This allows the user to quickly update the appropriate control.
If multiple validation controls fail and this property is set to true, the control specified in the ControlToValidate property for the first validation control receives focus.
What is the initial value property of a RequiredFieldValidator?
Use this property to specify the initial value of the input control. Validation fails only if the value of the associated input control matches this InitialValue upon losing focus.
Validation controls to check Web form data entries before the data is accepted and saved in the Database. Validation controls can be used to address the following questions.
1. Did the user enter anything?
2. Is the entry the appropriate kind of data (For example, Date of Birth should be a valid Date, Name should be a string, etc.)?
3. Is the data within a required range? (For example, age cannot be greater than 100 years)
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. Most validity problems can be caught and corrected by the user without a round-trip to the server.
Where do the ASP.NET validation controls validate data, on the Client or on the Web Server?
ASP.NET validation controls validate data first on the client and then on the webserver. If a client disables javascript on the browser then, client-side validations are bypassed and validations are performed on the webserver.
Client-side validation is provided by a JScript library named WebUIValidation.js, which is downloaded separately to the client. Validation controls also automatically provide server-side validation. Server-side validation is always performed, whether or not client-side validation has occurred. This double-checking ensures that custom validations are performed correctly and that client-side validation has not been circumvented.
What are the 6 different validation controls provided by ASP.NET?
RequiredFieldValidator: Checks whether a control contains data.
CompareValidator: Checks whether an entered item matches an entry in another control
RangeValidator: Checks whether an entered item is between two values.
RegularExpressionValidator: Checks whether an entered item matches a specified format.
CustomValidator: Checks the validity of an entered item using a client-side script or a server-side code, or both.
ValidationSummary:Displays validation errors in a central location or display a general validation error description
What property of the validation control is used to specify which control to validate?
ControlToValidate property.
Explain in simple steps how to use validation controls?
1. Draw a validation control on a Web form and set its ControlToValidate property to the control you want to validate.
2. If we are using the CompareValidator control then we need to specify the ControlToCompare property.
3.Set the validation control’s ErrorMessage property to the error message we want to be displayed if the control’s data is not valid.
4.Set the validation control’s Text property if we want the validation control to display a message other than the message in the ErrorMessage property when an error occurs. Setting the Text property lets us briefly indicate where the error occurred on the form and display the longer ErrorMessage property in a ValidationSummary control.
5. Draw a ValidationSummary control on the Webform to display the error messages from the validation controls in one place.
6. Provide control that triggers a postback event. Although validation occurs on the client-side, validation doesn’t start until a postback is requested.
Are the validation controls fired on the client-side if javascript is disabled on the client browser?
No, validation controls are not fired on the client-side if javascript is disabled on the client browser.
What is the use of CausesValidation property of an ASP.NET button control?
CausesValidation property of an ASP.NET button control is used to determine if the validation controls should be fired when the button is clicked. If CausesValidation property is set to true, then validation is performed and if the CausesValidation property is set to false then validation is not done.
Give an example of a real time scenario where you might use CausesValidation property of an ASP.NET button control?
1. Did the user enter anything?
2. Is the entry the appropriate kind of data (For example, Date of Birth should be a valid Date, Name should be a string, etc.)?
3. Is the data within a required range? (For example, age cannot be greater than 100 years)
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. Most validity problems can be caught and corrected by the user without a round-trip to the server.
Where do the ASP.NET validation controls validate data, on the Client or on the Web Server?
ASP.NET validation controls validate data first on the client and then on the webserver. If a client disables javascript on the browser then, client-side validations are bypassed and validations are performed on the webserver.
Client-side validation is provided by a JScript library named WebUIValidation.js, which is downloaded separately to the client. Validation controls also automatically provide server-side validation. Server-side validation is always performed, whether or not client-side validation has occurred. This double-checking ensures that custom validations are performed correctly and that client-side validation has not been circumvented.
What are the 6 different validation controls provided by ASP.NET?
RequiredFieldValidator: Checks whether a control contains data.
CompareValidator: Checks whether an entered item matches an entry in another control
RangeValidator: Checks whether an entered item is between two values.
RegularExpressionValidator: Checks whether an entered item matches a specified format.
CustomValidator: Checks the validity of an entered item using a client-side script or a server-side code, or both.
ValidationSummary:Displays validation errors in a central location or display a general validation error description
What property of the validation control is used to specify which control to validate?
ControlToValidate property.
Explain in simple steps how to use validation controls?
1. Draw a validation control on a Web form and set its ControlToValidate property to the control you want to validate.
2. If we are using the CompareValidator control then we need to specify the ControlToCompare property.
3.Set the validation control’s ErrorMessage property to the error message we want to be displayed if the control’s data is not valid.
4.Set the validation control’s Text property if we want the validation control to display a message other than the message in the ErrorMessage property when an error occurs. Setting the Text property lets us briefly indicate where the error occurred on the form and display the longer ErrorMessage property in a ValidationSummary control.
5. Draw a ValidationSummary control on the Webform to display the error messages from the validation controls in one place.
6. Provide control that triggers a postback event. Although validation occurs on the client-side, validation doesn’t start until a postback is requested.
Are the validation controls fired on the client-side if javascript is disabled on the client browser?
No, validation controls are not fired on the client-side if javascript is disabled on the client browser.
What is the use of CausesValidation property of an ASP.NET button control?
CausesValidation property of an ASP.NET button control is used to determine if the validation controls should be fired when the button is clicked. If CausesValidation property is set to true, then validation is performed and if the CausesValidation property is set to false then validation is not done.
Give an example of a real time scenario where you might use CausesValidation property of an ASP.NET button control?
Let us assume we have a Page that collects user information like firstName, lastName age, date of birth, gender with a submit and reset buttons. When I click the submit button the information filled in 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 we have to set the CausesValidation property of the reset button to false for the validation to be bypassed. Otherwise, we will not be able to post back the page to the server.
What is ASP.NET Custom Validator used for?
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.
How do you programmatically check, if the client-side validation is not bypassed by disabling the javascript on the client browser?
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.
How do you programmatically invoke all validation controls on a page?
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.
What is a validation group?
Validation groups allow us to group validation controls on a page as a set. Each validation group can perform validation independently from other validation groups on the page.
How do you create a validation group?
We create a validation group by setting the ValidationGroup property to the same name for all the controls we want to group. We can assign any name to a validation group, but we must use the same name for all members of the group.
Explain how a validation group works when the Page is posted by clicking a button?
During postback, the Page class's IsValid property is set based only on the validation controls in the current validation group. The current validation group is determined by the control that caused validation to occur. For example, if a button control with a validation group of LoginGroup is clicked, then the IsValid property will return true if all validation controls whose ValidationGroup property is set to LoginGroup are valid.
Can a DropDownList fire validation controls?
Yes, DropDownList control can also fire validation if the control's CausesValidation property is set to true and the AutoPostBack property is set to true.
How do you programmatically force all validation controls in a particular validation group to be fired?
Call the Page.Validate(string GroupName) method and pass the name of the validation group. This will fire only the validation controls in that validation group.
What is SetFocusOnError property of a validation control used for?
Use the SetFocusOnError property to specify whether the focus is automatically set to the control specified by the ControlToValidate property when this validation control fails. This allows the user to quickly update the appropriate control.
If multiple validation controls fail and this property is set to true, the control specified in the ControlToValidate property for the first validation control receives focus.
What is the initial value property of a RequiredFieldValidator?
Use this property to specify the initial value of the input control. Validation fails only if the value of the associated input control matches this InitialValue upon losing focus.
No comments:
Post a Comment