ONLINEPROOFINGSITE.COM

proofing tools for italian - www.onlineproofingsite.com

Menu


There are numerous types of validation controls in ASP.NET, including the following: RequiredFieldValidator: The RequiredFieldValidator


control is used to make a particular control a required entry. CompareValidator: The CompareValidator control compares the value of one control (numeric or string) with the value of another. You can also use this control to perform data-type checks. RangeValidator: The RangeValidator control checks to make sure that the value of a control (numeric or string) falls within a certain range. RegularExpressionValidator: The RegularExpressionValidator control checks for patterns using regular expressions that you write. Visit the following website for a list of commonly used regular expressions: http://regexlib.com/DisplayPatterns.aspx. ValidationSummary: Display a list of errors in a single alert box using the ValidationSummary control. The errors the ValidationSummary control displays are those returned by the preceding controls. You can insert a RequiredFieldValidator control into your application by following these steps: 1. Place your cursor next to the Name TextBox control and switch to Split view. 2. Select Tag from the Insert Menu. Navigate to ASP.NET Tags, select Validation Server Controls, and highlight RequiredFieldValidator, as shown in Figure 26.24. Figure 26.24. Select the RequiredFieldValidator control. 3. Click Insert. The RequiredFieldValidator's editor appears. 4. Give the RequiredFieldValidator the ID rfvName, enter the value name in the Control to Validate text box, and type the custom error message Name is required! as shown in Figure 26.25. Figure 26.25. Enter all the appropriate information for your validation control. [View full size image]   NOTE Notice that there are other options we're not modifying heresuch as Text, Display, Initial Value, and Enable Client Script. You can use these values to further customize the functionality for the particular validation control. For instance, if you wanted text to appear initially before the error appears, you could set the Text property with a custom text message. Or if you don't want your validation control to consume space on the form before it was displayed, you can set the Display property's value to Dynamic. Check the ASP.NET Reference in the Reference panel for a detailed explanation of the properties that the validation control supports. 5. Click OK to complete the property formatting of the RequiredFieldValidator control. 6. Click Close. Your new validation control should be inserted visually in the Designer and syntactically in the code for the page. 7. Save your work and test the results in the browser by pressing F12. Clicking the Submit button without typing a value for the Name field will result in an error message. 8. Repeat steps 17 until all the form controls have a RequiredFieldValidator control associated with them. CAUTION ASP.NET validation controls only fully work in Internet Explorer. If you use a browser other than Internet Explorer, you'll have to use server-side validation. To do this, simply uncheck the Enable Client Script check box in the Property Formatting dialog whenever you insert a validation control.