Professional Documents
Culture Documents
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
.
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
.
((.
RequiredFieldValidator :
InitialValue
InitialValue
.
RangeValidator :
.
:
Type --
Currency, Date, Double, Integer, and String.
. MinimumValue --
MaximumValue --
.
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
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
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
.
( ).