29
VALIDATION CONTROLS IN ASP.NET By:- Shishir Jain

Validation controls in asp

Embed Size (px)

DESCRIPTION

there are many validation controls we find into ASP.NET. These controls also called server validation controls. by using those controls we can validate our web applications some common properties also of these controls. they all are described into this presentation.

Citation preview

Page 1: Validation controls in asp

VALIDATION CONTROLS IN ASP.NET

By:- Shishir Jain

Page 2: Validation controls in asp

2

Validation Validation:- (valid data)

Check User Input Against a Set of rules

Validation Type:- Client Side Validation Server Side Validation

Page 3: Validation controls in asp

3

Validation Controls

Asp. Net Provides Some validation

controls . These Controls are similar to

other common controls and can be used

in the same way.

A Validation server control is used to

validate the data of an input control. If

the data does not pass validation, it will

display an error message to the user

Page 4: Validation controls in asp

4

Validation Server Controls

The syntax for creating a Validation server control is:

<asp:control_name id="some_id" runat="server" />

Page 5: Validation controls in asp

5

Validation Server Controls

Required Field Validator

Compare Validator

Range Validator

Regular Expression Validator

Custom Validator

Validation Summary

Page 6: Validation controls in asp

6

Validation Server Controls

Compare Validator :-Compares the value of

one input control to the value of another

input control or to a fixed value.

Required Field Validatior :-Makes an input

control a required field.

Range Validator :-Checks that the user

enters a value that falls between two values

Page 7: Validation controls in asp

7

Validation Server Controls

Regular Expression Validator :-Ensures that the

value of an input control matches a specified

pattern

Custom Validator :-Allows you to write a

method to handle the validation of the value

entered

Validation Summary:-Displays a report of all

validation errors occurred in a Web page

Page 8: Validation controls in asp

8

Required Field Validator Used to make an input control a required field.

Validation fails if the input value does not

change from its initial value. By default, the

initial value is an empty string ("").

Leading and trailing spaces of the input value

are removed before validation.

The InitialValue property does not set the

default value for the input control. It indicates

the value that you do not want the user to

enter in the input control.

Page 9: Validation controls in asp

9

Required Field Validator

Properties BackColor ControlToValidate:- id of Control Display:- None, Static, Dynamic EnableClientScript:- Boolean value Enabled: Bololean Value ErrorMessage: The text to display in the

ValidationSummary control when validation fails. This text will also be displayed in the validation control if the Text property is not set

Page 10: Validation controls in asp

10

Required Field Validator

ForeColor

Id :-A unique id for the control

InitialValue :- Specifies the starting value of

the input control. Default value is "“

Runat:- Specifies that the control is a server

control. Must be set to "server"

Text:- The message to display when validation

fails

Page 11: Validation controls in asp

11

Compare Validator

Used to compare the value of one input

control to the value of another input

control or to a fixed value.

If the input control is empty, the

validation will succeed. We can use the

RequiredFieldValidator control to make

the field required.

Page 12: Validation controls in asp

12

Compare Validator

Properties :-

BackColor

ControlToCompare :- The name of the control to

compare with

ControlToValidate :- The id of the control to validate

Display:- None ,Static , Dynamic

EnableClientScript :- Boolean value

Enabled:- A Boolean value that specifies whether the

validation control is enabled or not

Page 13: Validation controls in asp

13

Compare Validator ErrorMessage

ForeColor

Operator:-. The type of comparison to perform. The

operators are : Equal, GreaterThan, GreaterThanEqual,

LessThan, LessThanEqual, NotEqual, DataTypeCheck

Runat

Text

Type :- Specifies the data type of the values to compare.

The types are: Currency,Date,Double,Integer,String,

ValueToCompare :-A specified value to compare with

Page 14: Validation controls in asp

14

Range Validator Used to check that the user enters an input value that

falls between two values.

Possible to check ranges within numbers, dates, and

characters.

Validation will not fail if the input control is empty. Use

the RequiredFieldValidator control to make the field

required.

Validation will not fail if the input value cannot be

converted to the data type specified. Use the

CompareValidator control,

Page 15: Validation controls in asp

15

Range Validator

Properties BackColor ControlToValidate Display:- None, Static, Dynamic EnableClientScript Enabled ErrorMessage ForeColor id

Page 16: Validation controls in asp

16

Range Validator

MaximumValue:- Specifies the maximum value of

the input control

MinimumValue:- Specifies the minimum value of

the input control

RunAt

Type:-Specifies the data type of the value to check.

The types are: Currency, Date, Double, Integer,

String

Text:- The Message to be display when validation

fails,

Page 17: Validation controls in asp

17

Regular Expression Validator

Used to ensure that an input value matches a

specified pattern.

Both server and client-side validation are

performed unless the browser does not support

client-side validation or the EnableClientScript

property is set to false.

Validation will not fail if the input control is empty.

Use the RequiredFieldValidator control to make the

field required.

Page 18: Validation controls in asp

18

Regular Expression Validator

Properties

BackColor

ControlToValidate

EnableClientScript

Enabled

ErrorMessage

ForeColor

Id

Page 19: Validation controls in asp

19

Regular Expression Validator

RunAt Text ValidationExpression:-Specifies the

expression used to validate input control. The expression validation syntax is different on the client than on the server. JScript is used on the client. On the server, the language you have specified is used. Ex: e-mail, Zip Code, Country Code, Phone Number Etc.

Page 20: Validation controls in asp

20

Custom Validator

The CustomValidator control allows you

to write a method to handle the

validation of the value entered.

This control helps in implementing user

defined validations .

To Do this you have to write the user

defined function in the head section in

<script> tag

Page 21: Validation controls in asp

21

Custom Validator

Properties

BackColor

ClientValidationFunction :- Specifies the name of the

client-side validation script function to be executed. The

script must be in a language that the browser supports,

such as VBScript or JScript

With VBScript, the function must be in the form:

Sub FunctionName (source, arguments)

With JScript, the function must be in the form:

Function FunctionName (source, arguments)

Page 22: Validation controls in asp

22

Custom Validator

ControlToValidate Display EnableClientScript Enabled ErrorMessage ForeColor Id

OnServerValidate:- Specifies the name of the server-side validation script function to be executed

RunAt Text

Page 23: Validation controls in asp

23

Validation Summary

Used to display a summary of all validation errors occurred in a Web page.

Error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.

Page 24: Validation controls in asp

24

Validation Summary

Properties Display Mode:- How To Display The Summary.

Values are BulletList, List, SingleParagraph EnableClientScript Enabled ForeColor HeaderText:- A header in the

ValidationSummary control Id RunAt

Page 25: Validation controls in asp

25

Validation Summary

ShowMessageBox:- A Boolean value that

specifies whether the summary should be

displayed in a message box or not.

ShowSummary:- A Boolean value that

specifies whether the ValidationSummary

control should be displayed or hidden

Page 26: Validation controls in asp

26

Validation Controls

The BaseValidator Class: The

validation control classes inherit from the

BaseValidator class and inherit its

properties and methods. Therefore, it

would help to take a look at the

properties and the methods of this base

class, which are common for all the

validation controls:

Page 27: Validation controls in asp

27

Properties And Methods

ControlToValidate Display EnableClientScript Enabled ErrorMessage Text SetFocusOnError:- It indicates whether in

case of an invalid control, the focus should switch to the related input control.

ValidationGroup

Page 28: Validation controls in asp

28

References

www.msdn.microsoft.com www.w3schools.com Asp.Net By Bible

Page 29: Validation controls in asp

29

Thank You