Using The Validation Controls
Using The Validation Controls
Understanding Validation
Users might ignore an important field and leave it
blank.
Users might try to type a short string of nonsense to
circumvent a required field check, thereby creating
endless headaches on your end. E.g. Emails.
Users might make an honest mistake, such as
entering a typing error, entering a nonnumeric
character in a number field, or submitting the wrong
type of information.
CausesValidation Property
when the user clicks the button depends on the value of
the CausesValidation property:
If CausesValidation is false, ASP.NET will ignore
the validation controls, the page will be posted back,
and your event-handling code will run normally.
If CausesValidation is true (the default), ASP.NET
will automatically validate the page when the user
clicks the button.If any control fails to validate, ASP.NET
will return the page with some error information,
depending on your settings.
Contd
IsValid - After validation is performed, this
returns true or false depending on whether it
succeeded or failed.
Enabled - When set to false, automatic validation
will not be performed for this control when the
page is submitted.
EnableClientScript - If set to true, ASP.NET will
add JavaScript and DHTML code to allow clientside validation on browsers that support it.
CustomValidation Control
It has 3 important property
ControlToValidateThe ID of the form field being
validated.
TextThe error message displayed when validation
fails.
ClientValidationFunctionThe name of a client-side
function used to perform client-side validation.
Manual Validation
Manual Validation can be done in 3 ways:
1) Use your own code to verify values. In this case, you
wont use any of the ASP.NET validation controls.
2) Disable the EnableClientScript property for each
validation control. This allows an invalid page to be
submitted, after which you can decide what to do with
it depending on the problems that may exist.
3) Add a button with CausesValidation set to false. When
this button is clicked, manually validate the page by
calling the Page.Validate() method.