This document discusses validation controls in .NET, which determine if data entered into web controls is valid before processing. There are six main validation controls: RequiredFieldValidator, CompareValidator, RangeValidator, ValidationSummary, RegularExpressionValidator, and CustomValidator. Validation controls validate user input on both the client-side using JavaScript and server-side to prevent spoofing. They make validation easier by allowing declarative validation that is separate from input controls and provide a flexible extensible framework.
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
Â
Validation Controls in .NET
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra âMentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
3. VALIDATION CONTROLS IN .NET
ARJUN S R
Arjun.sr007@gmail.com
www.facebook.com/arjun.a
ryavartham
twitter.com/arjun.sr007
in.linkedin.com/in/arjun.sr0
07
9745649882
4. ⢠A validation control (or validator) determines whether the
data in another web control is in the proper format, before the
data is processed.
⢠When the XHTML for our page is created, the validator is
converted into JavaScript that performs the validation
⢠JavaScript is a scripting language that enhances the
functionality and appearance of web pages and is typically
executed on the client.
⢠Because some clients disable or do not support scripting,
ASP.NET validation controls can function on the client,
on the server or both.
5. WHAT VALIDATION CONTROLS
DO?
⢠Rich, declarative validation
⢠Validation declared separately from input control
⢠Extensible validation framework
⢠Supports validation on client and server
⢠Server-side validation is always done
â Prevents users from spoofing Web Forms
⢠Validate User inputs
ď75% of code for handling exceptions
ďSimplify task
7. 1. RequiredFieldValidator
ď Ensures that a value is entered
⢠<asp: RequiredFieldValidator
2. CompareValidator
â Compares input to: data type, constant, another control,
database value, etc
â <asp: CompareValidator>
3. RangeValidator
â Entry within a specified data range
â <asp: RangeValidator>
4. ValidationSummary
â Summarizes all errors on page
â <asp: ValidationSummary>
8. 4. RegularExpressionValidator
â Check format against a specific pattern
â E-mail address, phone number, zip code, etc
â <asp: RegularExpressionValidator>
5. CustomValidator
â Write own code
â Server- or client-side
â <asp: CustomValidator>
9. ⢠Validation controls are derived from
System.Web.UI.WebControls.BaseValidator, which is derived
from the Label control
⢠Validation controls contain text which is displayed only if validation fails
⢠Text property is displayed at control location
⢠ErrorMessage is displayed in summary
⢠Page.IsValid indicates if all validation controls on the page succeed
void Submit_click(object s, EventArgs e) {
if (Page.IsValid) {
Message. Text = "Page is valid!";
}
}
15. CustomValidator
⢠<asp: CustomValidator id=âvalCommentsâ
ControlToValidate=âtxtCommentsâ
Text=â(Comments must be less than 10 characters)â
OnServerValidate=âvalComments_ServerValidateâ
Runat=âserverâ />
16. BENEFITS AND LIMITATIONS
Benefits
â Convenience
⢠Cut & paste
â Bomb-proof
⢠Server-side validation
Limitations
â Must remember to check on server
⢠Page.IsValid statement
â Different interpretations of regular expressions
⢠JavaScript vs. server
⢠minor issue
17. SUMMARY
⢠Easy to use
⢠Flexible
â Validate any type of input
⢠Combines client- and server-side validation in one
control
⢠Bomb-proof server-side validation
18. this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com