Validation and Rich controls 1

Preview:

Citation preview

www.tech.findforinfo.com 1

Validation and Rich controls

www.tech.findforinfo.com 2

►Calendar control Formatting a calendar Restricting dates

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

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

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

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

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

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

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

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

www.tech.findforinfo.com 11

Adrotator

►The Adrotator displays a randomly selected image

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

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

www.tech.findforinfo.com 13

Property

Property DescriptionAdvertisement file

Relative path

Keyword filter

To filter the file

Target The target window or frame

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

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

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

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

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

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

www.tech.findforinfo.com 20

Validation classes

►System.Web.UI.WebControls namespace

►Validator controls are inherited from the BaseValidator class

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

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

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

www.tech.findforinfo.com 24

www.tech.findforinfo.com 25

www.tech.findforinfo.com 26

After setting the property to false

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

www.tech.findforinfo.com 28

www.tech.findforinfo.com 29

www.tech.findforinfo.com 30

Setting the property

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

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

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 =,>,<,>=,<=,<>

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

www.tech.findforinfo.com 35

Range Validator

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

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

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

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

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

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

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

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)

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

www.tech.findforinfo.com 44

RequiredFieldValidator

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

www.tech.findforinfo.com 45

Property

Property DescriptionInitialValue The initial value of the input

control and it is set to empty string

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

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

www.tech.findforinfo.com 48

Validation Summary

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

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

Recommended