validation controls asp .net
TRANSCRIPT
![Page 1: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/1.jpg)
![Page 2: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/2.jpg)
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
![Page 3: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/3.jpg)
VALIDATION CONTROLS IN .NET
ARJUN S [email protected]/
arjun.aryavarthamtwitter.com/arjun.sr007in.linkedin.com/in/arjun.sr0079745649882
![Page 4: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/4.jpg)
• 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.
![Page 5: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/5.jpg)
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 inputs75% of code for handling exceptionsSimplify task
![Page 6: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/6.jpg)
SIX VALIDATION CONTROLS
![Page 7: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/7.jpg)
1. RequiredFieldValidatorEnsures 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>
![Page 8: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/8.jpg)
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>
![Page 9: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/9.jpg)
• 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!"; } }
![Page 10: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/10.jpg)
RequiredFieldValidator
<asp: RequiredFieldValidator id=”reqFirstName” ControlToValidate=”txtFirstName” Text=”(Required)” SetFocusOnError=”true” Runat=”server” />
![Page 11: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/11.jpg)
CompareValidator
<asp: CompareValidator id=”cmpBirthDate” Text=”(Invalid Date)” ControlToValidate=”txtBirthDate” Type=”Date” Operator=”DataTypeCheck” Runat=”server” />
![Page 12: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/12.jpg)
RangeValidator
<asp: RangeValidator id=”reqAge” ControlToValidate=”txtAge” Text=”(Invalid Age)” MinimumValue=”5” MaximumValue=”100”
Type=”Integer” Runat=”server” />
![Page 13: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/13.jpg)
ValidationSummary
<asp: ValidationSummary id=”ValidationSummary1” ShowMessageBox=”true” ShowSummary=”false” Runat=”server” />
![Page 14: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/14.jpg)
RegularExpressionValidator
• <asp: RegularExpressionValidator id=”regEmail” ControlToValidate=”txtEmail” Text=”(Invalid email)” ValidationExpression=”\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*” Runat=”server” />
![Page 15: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/15.jpg)
CustomValidator
• <asp: CustomValidator id=”valComments” ControlToValidate=”txtComments”
Text=”(Comments must be less than 10 characters)” OnServerValidate=”valComments_ServerValidate” Runat=”server” />
![Page 16: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/16.jpg)
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
![Page 17: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/17.jpg)
SUMMARY
• Easy to use• Flexible– Validate any type of input
• Combines client- and server-side validation in one control
• Bomb-proof server-side validation
![Page 18: Validation controls ASP .NET](https://reader034.vdocuments.net/reader034/viewer/2022042502/554a3fcfb4c905863d8b4eb4/html5/thumbnails/18.jpg)
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