49
Validation and Rich controls 1 www.tech.findforinfo.com

Validation and Rich controls 1

Embed Size (px)

Citation preview

Page 1: Validation and Rich controls 1

www.tech.findforinfo.com 1

Validation and Rich controls

Page 2: Validation and Rich controls 1

www.tech.findforinfo.com 2

►Calendar control Formatting a calendar Restricting dates

Page 3: Validation and Rich controls 1

www.tech.findforinfo.com 3

The Calendar Control

►It is one of the most impressive controls

►It is called as rich control because it can be generated with a simple tag but it is rendered in dozens of HTML lines

Page 4: Validation and Rich controls 1

www.tech.findforinfo.com 4

Calendar controls -Default features

►Calendar control presents a single month view (User navigates)

►Each time the page is posted back and ASP.NET provides a new page

►The date is selected and it can be retrieved

►The day is retrieved as DateTime Object from the Calendar.SelectedDate property

Page 5: Validation and Rich controls 1

www.tech.findforinfo.com 5

Basic set of features

►Configuration of selection modes►Select entire month/week►Done using the

Calendar.SelectionMode property►Static calendar

Page 6: Validation and Rich controls 1

www.tech.findforinfo.com 6

Calendar control properties

Property DescriptionCaption Caption of the calendarCaptionAlign Alignment of the calendarCellPadding The space between the cell

walls and the contentCellspacing Space between cells

DayStyle The format for displaying days

NextPrevFormat

The format for next previous month links

Page 7: Validation and Rich controls 1

www.tech.findforinfo.com 7

Calendar control properties

Property DescriptionSelectedDate The selected dateSelectionMode

How a user is allowed to select dates

SelectorStyle The style for the month and week selection link

ShowGridLines

Boolean property

ShowTitle Boolean property

OnDayRender The name of the function to be executed when when each day cell is created

Page 8: Validation and Rich controls 1

www.tech.findforinfo.com 8

Formatting the calendar control

Property DescriptionHorizontal Align

Sets the contents with the horizontal alignment

Vertical Align Sets the contents with the vertical alignment

Wrap Specifies whether the contents are to be wrapped automatically or the cell is to be extended

Page 9: Validation and Rich controls 1

www.tech.findforinfo.com 9

Formatting the calendar control

Property Description

Horizontal Align

Sets the contents with the horizontal alignment

Vertical Align Sets the contents with the vertical alignment

Wrap Specifies whether the contents are to be wrapped automatically or the cell is to be extended

Page 10: Validation and Rich controls 1

www.tech.findforinfo.com 10

Formatting the calendar control

Property Description

DaysHeaderStyle The style for the days of the week

DayStyle The default style for the dates

NextPrev style The style for the navigation

OtherMonthDaysStyle

The style for the dates that are not currently displayed

SelectedDayStyle The style for the selected day

SelectorStyle The style for the selector controls

Page 11: Validation and Rich controls 1

www.tech.findforinfo.com 11

Adrotator

►The Adrotator displays a randomly selected image

►It contains the xml file that lists all the available images

Page 12: Validation and Rich controls 1

www.tech.findforinfo.com 12

Elements

Element DescriptionImageUrl The url for the image relative

urlNavigateUrl The link that will be followed

when the user clicks on the banner

Alternatetext The text that will be displayed if the picture cannot be displayed

Impression A number that set the appearance of the advertisement

Keyword Used for filtering the advertisements

Page 13: Validation and Rich controls 1

www.tech.findforinfo.com 13

Property

Property DescriptionAdvertisement file

Relative path

Keyword filter

To filter the file

Target The target window or frame

Page 14: Validation and Rich controls 1

www.tech.findforinfo.com 14

Specific values for the target

Target Description_blank The link opens a new unframed

window

_parent The link opens in the parent of the current frame

_self The link opens in the current frame

_top The link opens in the topmost frame of the current window

Page 15: Validation and Rich controls 1

www.tech.findforinfo.com 15

Validation controls

►Powerful tool to verify the user input and display custom error messages

►Five different validation controls inherited from the BaseValidator class

Page 16: Validation and Rich controls 1

www.tech.findforinfo.com 16

Why Validation

►User’s might ignore an important field and leave it blank

►Users might provide and invalid entry in to the input field

►Users might make a typing mistake(ie) a non-numeric value in the numeric field

Page 17: Validation and Rich controls 1

www.tech.findforinfo.com 17

Validation process

►The validator controls are used to verify a page automatically when the user submits it or manually in your code.

►The process The user receives the input form and tries to fill

up the input controls When finished the user clicks the button to

submit the page Every button control has a CausesValidation

property

Page 18: Validation and Rich controls 1

www.tech.findforinfo.com 18

CausesValidation property

►If this property is set to False,ASP.NET ignores the validation controls,the page will be posted back

►If this property is set to True,then the ASP.NET engine validates the page when the user clicks the button

►Each control is validated and if any controls fails to validate then the page is returned with some error

Page 19: Validation and Rich controls 1

www.tech.findforinfo.com 19

When does validation happen?

►It happens only when the button is click and not when the page is posted back

Page 20: Validation and Rich controls 1

www.tech.findforinfo.com 20

Validation classes

►System.Web.UI.WebControls namespace

►Validator controls are inherited from the BaseValidator class

Page 21: Validation and Rich controls 1

www.tech.findforinfo.com 21

Basic propertyProperty Description

ControlToValidate

Identifies the control to be validated

ErrorMessageForecolorDisplay

ErrorMessage is displayed when validation failsDisplay has two mode (Dynamic,Static)

IsValid Returns true or false based on validation

Enabled When set to false automatic validation will not take place

Page 22: Validation and Rich controls 1

www.tech.findforinfo.com 22

Validator Specific Properties

Property DescriptionRequiredFieldValidator

None required

RangeValidator Maximum,Minimum,TypeCompareValidator ControlToCompare,Operat

or,Type

RegularExpressionValidator

Validation Expression

CustomValidator ClientValidation FunctionServerValidate event

Page 23: Validation and Rich controls 1

www.tech.findforinfo.com 23

Server-Side Validation

►ASP.NET adds a javascript and DHTML code►Normally in all validation controls the error

message will be displayed when the focus changes

►To check the server-side validation set the RangeValidator.EnableClientScript property to false

► In this case the error message will be displayed only the button is clicked and the page will be returned from the server

Page 24: Validation and Rich controls 1

www.tech.findforinfo.com 24

Page 25: Validation and Rich controls 1

www.tech.findforinfo.com 25

Page 26: Validation and Rich controls 1

www.tech.findforinfo.com 26

After setting the property to false

Page 27: Validation and Rich controls 1

www.tech.findforinfo.com 27

Other Display options

►Use the Validation Summary control►The Range Validator Display property

is set to None►Set to display mode property to

message box then the Error messages are displayed in a message box

Page 28: Validation and Rich controls 1

www.tech.findforinfo.com 28

Page 29: Validation and Rich controls 1

www.tech.findforinfo.com 29

Page 30: Validation and Rich controls 1

www.tech.findforinfo.com 30

Setting the property

Page 31: Validation and Rich controls 1

www.tech.findforinfo.com 31

Manual Validation

►There are three ways to create manual validation

►Use your own code to validate the controls

►Disable the EnableClientScript property for each validation control.

►Add a button with CauseValidation property set to false.When the page is clicked the validation is clicked

Page 32: Validation and Rich controls 1

www.tech.findforinfo.com 32

Compare Validator

►This control compares the values in one input control with the other

►The type of comparison depends on the operator property

Page 33: Validation and Rich controls 1

www.tech.findforinfo.com 33

Property

Property DescriptionControltoValidate

Identifies the control to validate

ErrorMessage If validation fails the validator control will display the message

IsValid After validation is performed,this returns True or False based on the validation

ControlToCompare

The input control that contains the comparison value

Operator Specifies the type of comparison =,>,<,>=,<=,<>

Page 34: Validation and Rich controls 1

www.tech.findforinfo.com 34

Property

Property DescriptionType The data type of the values

that will be compared(String,Integer,double,Date,or currency)

ValueToCompare Instead of ControlToCompare,If both are set then ControlTocompare takes precedence

Page 35: Validation and Rich controls 1

www.tech.findforinfo.com 35

Range Validator

►This control checks whether the given value in the input control falls within the range

Page 36: Validation and Rich controls 1

www.tech.findforinfo.com 36

Property

Property DescriptionType The data type of the values that

will be compared(String,Integer,double,Date,or currency)

Maximum Value

The largest value

Minimum Value

The smallest value

Page 37: Validation and Rich controls 1

www.tech.findforinfo.com 37

RegularExpression validator

►This control checks whether the user entered value matches the specified the regular expression

►Property description Validation A string that

expression contains

the expression

Page 38: Validation and Rich controls 1

www.tech.findforinfo.com 38

Literals and Metacharacters

►All regular expressions are made up of two characters:Literals and Metacharacters

►In literals only the code is typed

Search for the string literal I you will find the character I

Page 39: Validation and Rich controls 1

www.tech.findforinfo.com 39

Metacharacters

►Consider the following expression►Del *.*►The above expression consists of one

literal (.) and two metacharacters(the asterisks)

►Translated as delete Any file With any number of characters With an extension of any number of

characters

Page 40: Validation and Rich controls 1

www.tech.findforinfo.com 40

Regular expression example

►\s denotes whitespace►\d represents any digit►Thus the following expression starts

with any expression that starts with the number 333 followed by a single white space and any three digits

►333\s\d\d\d

Page 41: Validation and Rich controls 1

www.tech.findforinfo.com 41

Delimiting range of characters

►Delimit by the square brackets►[a-f]►The above expression matches any

word that starts with the letter from “a” to “f” lowercase

Page 42: Validation and Rich controls 1

www.tech.findforinfo.com 42

Some of the common regular expression characters

Character Description

\s Any white space or tab

\S Any non-white space character

\d Any digit character

\D Any character that is not a digit

\w Any word character (letter,number,underscore)

Page 43: Validation and Rich controls 1

www.tech.findforinfo.com 43

Commonly Used Regular expression

Content Regular expression

Description

Email address \S+@+\S+\.\S+

Checks for symbol,non-white space character

Password length

\w{4,10} A password atleast four characters long and less than 10 characters

Social security Number

\d{3}-\d{2}-\d{4}

A sequence of digits as follows444-22-5555

Page 44: Validation and Rich controls 1

www.tech.findforinfo.com 44

RequiredFieldValidator

►This control checks whether the user has entered a value in the given control

Page 45: Validation and Rich controls 1

www.tech.findforinfo.com 45

Property

Property DescriptionInitialValue The initial value of the input

control and it is set to empty string

Page 46: Validation and Rich controls 1

www.tech.findforinfo.com 46

Custom Validator

►This control allows the user to enter their own validation algorithm

►Validation is performed to the server side by responding to the ServerValidate event

Page 47: Validation and Rich controls 1

www.tech.findforinfo.com 47

Property

Property DescriptionclientValidationFunction

A string that contains the function name

ServerValidate event

The code responds to the event and the object Server-ValidateEvent Args is received that contains the user entered values and specifies whether the validation succeded or not

Page 48: Validation and Rich controls 1

www.tech.findforinfo.com 48

Validation Summary

►This control displays a summary of all error messages for every validation control

Page 49: Validation and Rich controls 1

www.tech.findforinfo.com 49

Property

Property DescriptionDisplayMode Set the format for the

validation summary text (List,SingleParagraph,BulletList)

Headertext Sets the header to the control

showMessageBox

When set to true the validation summary will be displayed in a message box