420 likes | 715 Views
Working with Validation Controls. What is Validation Controls? Why we should use them?
E N D
What is Validation Controls? • Why we should use them? • Lots of questions are take place in your mind now hear is the solution for it. Validation Controls name suggest that it is related to validate something but yet it is not clear that what we should validate. Answer is that when you create any form in your application. There should have several restrictions regarding your requirement
For Example: • When you create a form for Personal Information below thing should be validate before you add this value in to database. • Name should not be Blank. • Age should be in number. • Age should be in between numeric range. • Email, Pin code should be in specific format etc.
These types of Validations are used when we create forms. Now it’s little bit clear in your mind that why we use Validation control but how to validate them is not clear. It can be done through two ways • Client Side Validation. • Server Side Validation.
What is Client Side Validation? • Client Side Validation can be done through JavaScript. The Advantages of the client side validation is that it should not make round trip to server that will validate through your browser so it will take less time than server side validation.
What is Server Side Validation? • while when we use server side validation that will make a round trip to server and than give call back that whether it is validate or not means this will take a more time than client side validation. • But it is more secure than client side validation because some time if your browser will not support some version of JavaScript than it will not validate perfectly while here in that case we are secure because this will defiantly occur.
Client Side Validation vs Server Side Validation: Client Side Validation: • Client Side validation will occur in Browser. • Client Side validation will take less time for execution. • Client side validation is not secure as server side. • Client side validation will not work if your browser will not support JavaScript.
Server Side Validation: • Server Side validation will occur in Server. • Server Side validation will take more time than client side execution. • Server side validation is more secure than Client side validation. • Server side validation will always execute because it is not depended on browser.
Asp.Net Validation controls: • Asp.Net Provide the validation control to validate your form in both way client side Validation as well as server Side Validation. If the user is working with a browser that supports dynamic HTML (DHTML), ASP.NET validation controls can perform validation using client script. Because the controls can provide immediate feedback without a round trip to the server, the user experience with the page is enhanced.
The controls automatically detect if the browser supports DHTML and perform their checking accordingly.
With ASP.NET, there are six validation controls included. They are: • The RequiredFieldValidation Control. • The CompareValidator Control. • The RangeValidator Control. • The RegularExpressionValidator Control. • The CustomValidator Control. • Validation Summary Control
RequiredFieldValidator : • RequiredFieldValidator control is used in a web form to check whether a control has a value. Typically, we use this control with a TextBox control. However, it can also use with other control such as RadioButton, CheckBox etc.
Example: Do the following steps. Take following items from the ToolBox. • A Label • A TextBox • A Button • A Require Field validator control and put it near to TextBox
After set all property as shown in above Table click on add button if you are not fill the value in textbox bellow error message will show.
CompareValidator : • The CompareValidator control is use for the purpose of comparison of two fields that can be values of textbox , radio button or dropdown list etc. in short you can compare two values. If that will not match than it will raise the error.
Example : • Do the following steps. • Take following items from the ToolBox. • 1) Two Label. • 2) Two TextBox. • 3) A Button. • 4) A Compare Field validate control.
After set all property as shown in above Table click on Compare button if you are not fill the value in textbox bellow error message will show.
RangeValidator Control • This control is use to check whether the value of a form field are between a minimum and maximum value. The minimum and maximum values can be dates, number currency amounts or strings
Example : • Do the following steps. • Take following items from the ToolBox. • 1) Two Label. • 2) Two TextBox. • 3) A Button. • 4) A RangeValidator Control. • Set the following property of above controls.
After set all property as shown in above Table click on Submit button if you are not fill the value in textbox bellow error message will show.
RegularExpressionValidator : • This validation control use to match the value entered into a form field to a regular expression. You can use this control to check whether a user has entered, for example a valid-Email address, telephone number, or username or password.
CustomValidator Control : • CustomValidator name suggest its meaning. By default what kind of validation you require that can not be judged all the time so Microsoft .Net provide the facility of custom validation. Here you can create your own custom validation according to your requirements.
Validation Summary Control: • Assume that there are more than thirty fields in your form. If you use validation controls for displaying error that it will be difficult for the any user to read it out so to solve this problem Microsoft add new validation control which is known as validation summary control. It’s name reflected its meaning. This control will show the list of the error message of your form so that it should be easy to see the error and use can fill form perfectly.