Validation controls ASP .NET

2,005 views

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,005
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
43
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Validation controls ASP .NET

  1. 1. Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  2. 2. VALIDATION CONTROLS IN .NETARJUN S RArjun.sr007@gmail.comwww.facebook.com/arjun.aryavarthamtwitter.com/arjun.sr007in.linkedin.com/in/arjun.sr0079745649882
  3. 3. • A validation control (or validator) determines whether thedata in another web control is in the proper format, before thedata is processed.• When the XHTML for our page is created, the validator isconverted into JavaScript that performs the validation• JavaScript is a scripting language that enhances thefunctionality and appearance of web pages and is typicallyexecuted 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.
  4. 4. WHAT VALIDATION CONTROLSDO?• 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
  5. 5. SIX VALIDATION CONTROLS
  6. 6. 1. RequiredFieldValidator Ensures that a value is entered• <asp: RequiredFieldValidator2. 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>
  7. 7. 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>
  8. 8. • Validation controls are derived fromSystem.Web.UI.WebControls.BaseValidator, which is derivedfrom 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 succeedvoid Submit_click(object s, EventArgs e) {if (Page.IsValid) {Message. Text = "Page is valid!";}}
  9. 9. RequiredFieldValidator<asp: RequiredFieldValidator id=”reqFirstName”ControlToValidate=”txtFirstName” Text=”(Required)”SetFocusOnError=”true” Runat=”server” />
  10. 10. CompareValidator<asp: CompareValidator id=”cmpBirthDate” Text=”(Invalid Date)”ControlToValidate=”txtBirthDate” Type=”Date”Operator=”DataTypeCheck” Runat=”server” />
  11. 11. RangeValidator<asp: RangeValidator id=”reqAge” ControlToValidate=”txtAge”Text=”(Invalid Age)” MinimumValue=”5” MaximumValue=”100”Type=”Integer” Runat=”server” />
  12. 12. ValidationSummary<asp: ValidationSummary id=”ValidationSummary1” ShowMessageBox=”true”ShowSummary=”false” Runat=”server” />
  13. 13. RegularExpressionValidator• <asp: RegularExpressionValidator id=”regEmail”ControlToValidate=”txtEmail” Text=”(Invalid email)”ValidationExpression=”w+([-+.’]w+)*@w+([-.]w+)*.w+([-.]w+)*”Runat=”server” />
  14. 14. CustomValidator• <asp: CustomValidator id=”valComments”ControlToValidate=”txtComments”Text=”(Comments must be less than 10 characters)”OnServerValidate=”valComments_ServerValidate”Runat=”server” />
  15. 15. BENEFITS AND LIMITATIONSBenefits– Convenience• Cut & paste– Bomb-proof• Server-side validationLimitations– Must remember to check on server• Page.IsValid statement– Different interpretations of regular expressions• JavaScript vs. server• minor issue
  16. 16. SUMMARY• Easy to use• Flexible– Validate any type of input• Combines client- and server-side validation in onecontrol• Bomb-proof server-side validation
  17. 17. this presentation helped you, please visit ourpage facebook.com/baabtra and like it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com

×