Reputation:
What is the difference between Page.Validate
and Page.IsValid
?
I read some articles about that
Page.Validate method is fired automatically by controls that have the CausesValidation property set to true(Which is default value for Button control).
Page.IsValid property tells you whether the validation succeeded or not.
But Which one is better? what was the relation between us?
Upvotes: 4
Views: 7500
Reputation: 460158
Page.Validate
is a method, Page.IsValid
is a property. The former forces validation of one or all validation-groups (if no group is specified), the latter returns the result of this validation.
You don't need to call Page.Validate
manually if the control that caused the postback has CausesValidation
set to true(default).
Q: Why would you want to force validation on serverside at all or why would you want to set CausesValidation
to false
?
A: Sometimes you don't want to force validation on clientside always but only under certain conditions that are checked on serverside. Or you want to combine multiple validation-groups.
Upvotes: 8