Presentation is loading. Please wait.

Presentation is loading. Please wait.

VALIDATION CONTROLS.  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt.

Similar presentations


Presentation on theme: "VALIDATION CONTROLS.  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt."— Presentation transcript:

1 VALIDATION CONTROLS

2  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt to fix the existing problems with the validation model.  Though Validation controls are server side objects, they can generate the client side script necessary to notify the user of an error immediately after they submit the form, before the browser contacts the server.  All the validation controls inherit from the base class BaseValidator, so all have a series of common properties and methods.

3  These are :- ControlToValidate : The ID of the control that this validator validates. ErrorMessage : This is the message that will be displayed in the validation summary. IsValid : A Boolean value that indicates whether the control specified by ControlToValidate is determined to be valid. Display : It has three possible values : Dynamic, Static and None. Dynamic : means that the space the control uses is’nt reserved for the control. Static : means that the space it uses is always reserved for the control. None : makes the control invisible.

4  There are six validation controls :- RequiredFieldValidator CompareValidator RangeValidator RegularExpressionValidator CustomValidator ValidationSummary

5 RequiredFieldValidator  It is used to make sure that the user enters some information in a field.  This validation control can also be used to prompt message to the user if he or she has left any input field with its default value.  To validate a required entry : Add a RequiredField Validator control to the page & set the following properties : PropertyDescription ControlToValidateThe ID of the control for which the user must provide a value. ErrorMessage, Text, DisplayProperties that specify the text and location of the error or errors that will appear if the user skips the control.

6  Add a test in your ASP.NET Web page code to check for validity If Page.IsValid Then e1.Text = “Required Field is filled” Else e1.Text = “Required Field is empty” End If

7 CompareValidator  It can be used in two ways :-  It can be used to make sure that the user enters identical data in two input fields.  A typical and often used case is password matching.  It can also be used to check for comparisons such as equality, greater than, less than etc.  In addition you can check whether the data entered in the input field is of the datatype as specified by you.  To validate against a specific value.  Add a CompareValidator Control to the page and set the following properties:

8 PropertyDescription ControlToValidateThe ID of the control for which the user must provide a value. ErrorMessage, Text, Properties that specify the text and location Display of the error or errors that will appear if the user skips the control. ValueToCompareA specified value to compare with ControlToCompareThe name of the control to compare with TypeSpecifies the data type of the values to compare. The types are: Currency,Date,Double,Integer,String OperatorThe type of comparison to perform. The operators are : Equal, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, NotEqual, DataTypeCheck  Add a test in your ASP.NET Web page code to check for validity If Page.IsValid Then e1.Text = “CompareValidator is correct” Else e1.Text = “CompareValidator is wrong” End If

9 RangeValidator  You can use the ASP.NET RangeValidator Control to determine whether a user’s entry falls within a specific range of acceptable values. For eg. between two numbers, between two dates, between two alphabetic characters.  You set the lower and upper bounds of the range as properties of a RangeValidator Control  You must also specify the datatype of the values that the control will validate.  To validate against a range of values : Add a RangeValidator Control to the page and set the following properties : PropertyDescription ControlToValidateThe ID of the control for which the user must provide a value. ErrorMessage, Text, DisplayProperties that specify the text and location of the error or errors that will appear if the user skips the control.

10 MaximumValueSpecifies the maximum value of the input control MinimumValueSpecifies the minimum value of the input control TypeSpecifies the data type of the values to check. The types are: Currency,Date,Double,Integer,String

11 RegularExpressionValidator  The RegularExpressionValidator Control confirms that the entry matches a pattern defined by regular expression.  You can check the Validation of the commonly performed formats such as social security numbers, email addresses, telephone numbers & postal code.  To validate against a Regular Expression : Add a RegularExpressionValidator control to the page and set the following properties : PropertyDescription ControlToValidateThe ID of the control for which the user must provide a value. ErrorMessage, Text, DisplayProperties that specify the text and location of the error or errors that will appear if the user skips the control.

12  Set the pattern to compare to by setting the ValidatationExpression property to a regular expression.  If you want to allow multiple valid patterns, use the bar character(|) to separate expressions.

13 CustomValidator  If existing ASP.NET validation controls do not suit your needs, you can define a custom function and call it using the CustomValidator Control.  Two validation functions can be performed using Custom validation control : first on the server side and second on the client side.  These functions contain logic defined by you to validate the input fields.  You should perform server side validation even if you use the client side check.  To validate on the server using a custom function : Add a CustomValidator Control to the page and set the following properties PropertyDescription ControlToValidateThe ID of the control for which the user must provide a value. ErrorMessage, Text, DisplayProperties that specify the text and location of the error or errors that will appear if the user skips the control.

14 Create a server based event handler for the control’s ServerValidate event. This event is called to perform the validation.The method has the signature as follows : Protected Sub CustomValidator1_ServerValidate(ByVal _source as System.Object, ByVal Args as _ System.Web.UI.WebControls.ServerValidateEventArgs)_Handles CustomValidator1.ServerValidate End Sub The source parameter is a reference to the CustomValidation control raising this event. The property args.value will contain the user input to validate. Set args.IsValid to true if the value is valid, otherwise false. Protected Sub TextValidate(……) args.IsValid=(args.Value.Length >=8) End Sub

15 Bind the event handler to the method using code such as the following : <asp:customValidator id=“customValidator1” runat=“server” onServerValidate=“TextValidate” ControlToValidate=“TextBox1” ErrorMessage=“Text must be 8 or more characters”/>  Add a test in your ASP.NET Web page to check for validity : To create custom validation logic on the client function validateLength(Osrc,args) { if(args.Value.length > 8) { args.IsValid=true } else { args.IsValid=false } Set ClientValidationFunction property to the name of the function that performs the client-side validation.

16 ValidatonSummary  Displays a summary of all validation errors inline on a web page, in a message box or both.  The ValidationSummary Control is used to summarize the error messages from all validators on a web page in a single location.  You can summarize the error messages from a group of validators on a web page by assigning the ValidationSummary Control to a validation group by setting the ValidationGroup property.  The summary can be displayed as a list, as a bulleted list, or as a single paragraph, based on the DisplayMode property.  The Summary can be displayed on the web page and in a message box by setting the ShowSummary and ShowMessageBox properties respectively.


Download ppt "VALIDATION CONTROLS.  Validation Controls are primarily used to validate, or verify the data entered by user into a web form.  Validation controls attempt."

Similar presentations


Ads by Google