• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Chapter 9
 

Chapter 9

on

  • 652 views

 

Statistics

Views

Total Views
652
Views on SlideShare
652
Embed Views
0

Actions

Likes
1
Downloads
28
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Chapter 9 Chapter 9 Presentation Transcript

    • • Understanding Validation• Validation Controls• BaseValidator Class Properties• Validator Specific Properties• Validating with Regular Expressions• Regular Expression Characters• Commonly used Regular Expressions• Validation Summary Control• Manual Validation• Validation Groups
    • Validation means ensuring that the data inserted into anapplication satisfies defined formats and other input criteria.Some possible mistakes a user can make:• 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.• Enter a nonnumeric character in a number field.• Malicious users might try to exploit a weakness in your code by entering carefully structured wrong values
    • ASP.NET provides five validator controls. Four aretargeted at specific types of validation, while the fifthallows you to apply custom validation routines
    • All the validation controls are found in the System.Web.UI.WebControlsnamespace and inherit from the BaseValidator class.Property DescriptionControlToValidate Identifies the control that is to be validatedError Message If validation fails, the validator control can display a text message set by this propertyForeColor By changing the ForeColor, you can make the error message stand outDisplay Dynamic, Static or NoneIsValid Returns true or false depending on whether it succeeded or failedEnabled When set to false, automatic validation will not be performed for this control when the page is submittedEnableClientScript If set to true, ASP.NET will add JavaScript and DHTML code to allow client-side validation on browsers that support it.
    • One of ASP.NET’s most powerful validation controls is theRegularExpressionValidator, which validates text by determiningwhether it matches a specific pattern.333sddds represents any whitespace character (such as a space or tab). drepresents any digitYou can use the plus (+) sign to represent a repeated character. Forexample, 5+7 means “one or more occurrences of the character 5,followed by a single 7.” The number 57 would match, as would555557The following expression would match any word that starts with aletter from a to f, contains one or more “word” characters (letters),and ends with ing—possible matches include acting and developing.[a-f]w+ing
    • In some modern browsers, ASP.NET automaticallyadds JavaScript code for client-side validation. In thiscase, when the user clicks a CausesValidation button,the same error messages will appear without the pageneeding to be submitted and returned from the server.This increases the responsiveness of your web page.However, even if the page validates successfully onthe client side, ASP.NET still revalidates it when it’sreceived at the server.
    • What happens when the user clicks a button :• If CausesValidation is false, ASP.NET will ignore thevalidation controls, the page will be posted back, andyour event handling code will run normally.• If CausesValidation is true (the default), ASP.NET willautomatically validate the page when the user clicksthe button. It does this by performing the validation foreach control on the page. If any control fails tovalidate, ASP.NET will return the page with some errorinformation. Your click event handling code may ormay not be executed.Use IsValid property in a conditional logic and writeevent handling code inside it.
    • Accommodates all the error messages from all thevalidation controls at a suitable location normally at thebottom of the page.Error messages from all the validators are hided bysetting their Display property to None.When you run the page, you won’t see any dynamicmessages as you enter invalid information andtab to a new field. However, when you click the OKbutton, the ValidationSummary will appear with a listof all error messages.It automatically retrieves the value of the ErrorMessageproperty from each validator
    • In some cases, you’ll want to display a full message inthe summary and some sort of visual indicator next tothe offending controlYou can use this technique with the help of the Textproperty of the validators. Ordinarily, Text is left empty,and the validator doesn’t show any content in the webpage. However, if you set both Text and ErrorMessage,the ErrorMessage value will be used for the summarywhile the Text value is displayed in the validator.Of course, you’ll need to make sure you aren’t alsosetting the Display property of your validator to None.
    • Manual validation is when you disable validation and performthe work on your own. This allows you to create a specializederror message of your own.You can create manual validation in one of three ways:I. Use your own code to verify values. In this case, you won’t use any of the ASP.NET validation controls.II. 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 itdepending on the problems that may exist.III. Add a button with CausesValidation set to false. When this button is clicked, manually validate the page by calling the Page.Validate() method. Then examine the IsValid property, and decide what to do.
    • Every control that provides a CausesValidation propertyalso includes the ValidationGroup property.In some situations you might have several distinct groups ofcontrols, possibly in separate panels and you may want toperform validations separately.To create a validation group, you need to set theValidationGroup property of every control in the samelogical group with the same descriptive string.