0% found this document useful (0 votes)
21 views14 pages

Asp Validaite

The document discusses ASP.NET validation controls that validate user input on the client-side and server-side. It describes common validation controls like RequiredFieldValidator, RangeValidator, CompareValidator, and RegularExpressionValidator. It also discusses how validation is triggered during postbacks and how the ValidationSummary control works. Custom validation is explained as validating conditions not covered by the other controls using JavaScript server-side validation.

Uploaded by

attigreda6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views14 pages

Asp Validaite

The document discusses ASP.NET validation controls that validate user input on the client-side and server-side. It describes common validation controls like RequiredFieldValidator, RangeValidator, CompareValidator, and RegularExpressionValidator. It also discusses how validation is triggered during postbacks and how the ValidationSummary control works. Custom validation is explained as validating conditions not covered by the other controls using JavaScript server-side validation.

Uploaded by

attigreda6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

(IT

Validation Controls

ASP.NET

Email:-nabil299@gmail.com
:

Client-Side
PostBack (JScript )
..
PostBack

Client-Side

JScript
Server-Side Validation .

ASP.NET
Validation controls
.

..
.

Validation controls :
ToolBox Validation tab

PostBack
.

:
RequiredFieldValidator : --
. Submit
RangeValidator : -
..

-- CompareValidator :
...

-- RegularExpressionValidator :
..

-- CustomValidator
JScript .. ASP.NET
.

-- ValidationSummary :
.

textbox RangeValidator
.. textbox
. RequeredFieldValidator

textbox ..
InputText DropDownList
value InputText DropDownList
text .. textbox
DropDownList
.. Value

CheckBox RadioButton
.

The Validation Process :

Submit Submit
True) CausesValidation
false CauseValidation
true
.
postback true CausesValidation
TextChanged
.

BaseValidator ValidationControls
..

BaseValidator :
. ControlToValidate : --

: Display:

Static :
.

Dynamic :

None :
Postback !!
. postback
. ValidationSummary

Enabled : --
false . True

ErrorMessage : --
String . ValidationSummary

Text : --
.
(ErrorMessage) Text

((IsValid(): --
! Privat Function() ..
:
10
Label ..
RunTime
Client-Side Validation
. postback
postback
!)..

.
false true IsValid()
:

If Validator.IsValid Then
Label1.Text = TextBox1.Text * 10
EndIf
ID . Validator

()IsValid :
true ()IsValid
false
.

font BackColor ForeColor --

((.
RequiredFieldValidator :

InitialValue
InitialValue
.

<asp:TextBox runat="server" ID="Name" />


<asp:RequiredFieldValidator runat="server"
ControlToValidate="Name"
Display="dynamic">Name is required
</asp:RequiredFieldValidator>
Submit "Name is required"
name ..

RangeValidator :

.
:
Type --
Currency, Date, Double, Integer, and String.

. MinimumValue --
MaximumValue --
.

<asp:RangeValidator runat="server" Display="dynamic"


ControlToValidate="DayOff" Type="Date"
MinimumValue="08/05/2005 MaximumValue="08/20/2005>Day Off is not within
the valid range
</asp:RangeValidator>

DayOff
20
.

CompareValidator :

...
.

!!
:
Type The RangeValidator --
..
Currency, Date, Double, Integer, and String .

type
.

.. :
CompareValidator
:

String Type
. Integers

"
!

..
type string

type
..

ValueToCompare --
.

ControlToCompare --
...

Operator --
DataTypeCheck Equal, NotEqual, GreaterThan, GreaterThanEqual,
LessThan, LessThanEqual, and

DataTypeCheck
Type

:
<asp:CompareValidator runat="server" Display="dynamic"
ControlToValidate="Age" ValueToCompare="18"
ErrorMessage="You must be at least 18 years old"
Type="Integer" Operator="GreaterThanEqual">*
</asp:CompareValidator>

:
<asp:CompareValidator runat="server"
ControlToValidate="Password2" ControlToCompare="Password"
ErrorMessage="The passwords don't match"
Type="String" Display="dynamic">
</asp:CompareValidator>
.

RegularExpressionValidator Control :

. URL

.Com HTTP URL


.

ValidationExpression
. Internet URL :Internet E-mail Address

... ..

. ..
MetaCharacters
.

CustomValidator Control :

Leap Year ..
CustomValidator .
False IsValid()
.

JScript

. txtleapyear

CustomValidator1_ServerValidate

args.isvalid args.value
. true

false 4
page.isvalid() args.isvalid
false .

: ServerValidate
Dim i As Integer = CInt(args.Value)
If (i Mod 4) = 0 Then

args.IsValid = True

Else

args.IsValid = False

End If

ValidationSummary
.

ValidationSummary Control :

ErrorMessage
. ValidationGroup
(messageBox)
PostBack Jscript)
true . ShowMessageBox

true . ShowSummary
.
:
List SingleParagraph DisplayMode : :
BulletList.
HeaderText .

messagebox ValidationSummary

.. ValidationSummary
None . Display
page Validators Collection
:
:
For Each ctrl As BaseValidator In Page.Validators

ctrl.Enabled = False

Next

:
..

CausesValidation
postback false
.

:
Me.Validate()
For Each ctrl As BaseValidator In Me.Validators

If ctrl.IsValid = False Then

Dim X As TextBox =
CType(Page.FindControl(ctrl.ControlToValidate), TextBox)
X.BackColor = Drawing.Color.Red
End If

Next

. :

ctrl :
.
:
IsValid()
false >>
TextBox X :
: ..

ID Page FindControl
Control

CType Control
textBox X Textbox Control
Ctrl . X
X :
.

Validation Groups :
..
. Panels ..

LogIn
..

.. submit
! ..

Validation Groups..
ValidationGroup
.. panel submit
ValidationGroup

login ValidationGroup
reg ValidationGroup
...
ValidationGroup submit

. ValidationGroup

. ValidationGroup
Validation ..
ValidationGroup submit Groups
postback
.
.: ..
RangeValidator
ValidationGroup
ValidationGroup
submit
.

ValidationGroup
. submit

submit
))

Page.Validate()
validationgroup
. page.isvalid
page.validate("groupname")

OverLoading Page.Validate()
validatiogroup
.

Page.Validate("group1")

() :
true
page.validate
false true page.isvalid
.
( ).

You might also like