/
ASP.NET Validation Controls ASP.NET Validation Controls

ASP.NET Validation Controls - PowerPoint Presentation

kimberly
kimberly . @kimberly
Follow
64 views
Uploaded On 2024-01-03

ASP.NET Validation Controls - PPT Presentation

Naveen Papagari Presentation Id 13 Validating user input Goals Check validity of data from the end user Why To maintain data integrity How Check user input on the client side ID: 1038017

control validation server asp validation control asp server button side errormessage validator click controls page runat syntax input section

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "ASP.NET Validation Controls" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. ASP.NET Validation ControlsNaveen PapagariPresentation Id #13Validating user input

2. GoalsCheck validity of data from the end userWhyTo maintain data integrityHowCheck user input on the client side or on the server sideExamplesIs the name Textbox empty?Does the email Textbox contain a structurally valid email address?

3. Client Side Vs Server SideClient-side validationDone in the browserUses JavaScriptDoes not require HTTPrequest + responseServer-side validationDone on the serverUses C#Requires HTTP request+ response

4. RequiredFieldValidatorInput field cannot be emptyCompareValidatorCompare between user inputs using =, >, etc.RangeValidatorMinimum < input < maximumRegularExpressionValidatorCheck the entry matches a pattern defined by the regular expressionCustomValidatorMake your own validatorValidationSummaryDisplays all error messages from validators in one spotASPNET Validation Controls

5. ControlToValidateThe control to be validatedErrorMessageThe message used in the ValidationSummaryTextThe error message used in the validation controlCssClassStyle appearance of the messagesCommon Properties of Validation Controls

6.  The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box.The syntax for the control:<asp:RequiredFieldValidator ID="rfvcandidate" runat="server" ControlToValidate="ddlcandidate"ErrorMessage="Please choose a candidate"InitialValue="Please choose a candidate"></asp:RequiredFieldValidator>Required Field Validator

7.  The CompareValidator control compares a value in one control with a fixed value, or, a value in another control. It has the following specific properties:The basic syntax for the control:<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"></asp:CompareValidator>Compare Validator

8.  The RangeValidator control verifies that the input value falls within a predetermined range. It has three specific properties:The syntax for the control:<asp:RangeValidator ID="rvclass" runat="server" ControlToValidate="txtclass" ErrorMessage="Enter your class (6 - 12)" MaximumValue="12" MinimumValue="6" Type="Integer"></asp:RangeValidator>Range Validator

9.  The RegularExpressionValidator allows validating the input text by matching against a pattern against a regular expression. The regular expression is set in the ValidationExpression property. The following table summarizes the commonly used syntax constructs for regular expressions:Regular Expression Validator<asp:RegularExpressionValidator ID="RegExpVal2" runat="server" ErrorMessage = "Please Enter Valid Email ID“ ValidationGroup="vgSubmit" ControlToValidate="txtEmail" CssClass="requiredFieldValidateStyle" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> </asp:RegularExpressionValidator>

10.  The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation. The server side validation routine should be written in any .Net language, like C# or VB.Net.The basic syntax for the control:<asp:CustomValidator ID="CustomValidator1" runat="server"ClientValidationFunction=.cvf_func. ErrorMessage="CustomValidator"></asp:CustomValidator>Custom Validator

11.  The ValidationSummary control does not perform any validation but shows a summary of all errors in the page. The summary displays the values of the ErrorMessage property of all validation controls that failed validation. Using Page.IsValid property we can check for page errors. When there are no errors IsValid returns true and user can proceed to next page.if (Page.IsValid){ //validation complete proceed }runat="server"The syntax for the control:<asp:ValidationSummary ID="ValidationSummary1" DisplayMode = "BulletList" ShowSummary = "true" HeaderText="Errors:" />Validation Summary

12. Base Validator Class

13. Validation Grouphttp://csharp-video-tutorials.blogspot.comSecond problem = when I click the Login button, only fields in the Login section (Username & Password) needs to be validated. Along the same lines when I click the "Register" button, only fields in the Registration section(Email, Username, Password and ConfirmPassword) needs to validated. If we don't use validation groups, then by default, whenever, you click any button, all the validation controls on the page get validated.So, when you click the login button, and if you want only, the fields in the Login section(Username and Password) to be validated, then set, the Validationgroup property of the validation controls and the login button control to the same group name. Use a different group name for the validation controls and register button, in the registration section.First Problem: when I click the Clear button, Form validation still happens. When I click the clear button, I just want to clear the textboxes in the Registration section. Validations doesn't make any sense here. So, how do I prevent validation from happening? Answer: CausesValidation=“False”

14.

15.