While this exception can be gracefully handled as demonstrated in the previous tutorial, ideally the editing or inserting user interface would include validation controls to prevent a user from entering such invalid data in the first place.
In order to provide a customized editing or inserting interface, we need to replace the Bound Field or Check Box Field with a Template Field.
Specifically, this tutorial takes the example created in the Examining the Events Associated with Inserting, Updating, and Deleting tutorial and augments the editing and inserting interfaces to include appropriate validation.
In the Examining the Events Associated with Inserting, Updating, and Deleting tutorial we created a page that listed the names and prices of the products in an editable Grid View.
Additionally, the page included a Details View whose , thereby always rendering in insert mode.
From this Details View, the user could enter the name and price for a new product, click Insert, and have it added to the system (see Figure 1).
NET 2.0 has added a number of improvements, the main two being client-side script support for browsers other than Internet Explorer and the ability to partition validation controls on a page into validation groups. To accomplish this, click on the Edit Templates link from the Grid View's smart tag to bring up the template editing interface.For more information on the new validation control features in 2.0, refer to Dissecting the Validation Controls in ASP. From here, you can select which template to edit from the drop-down list.Since we want to augment the editing interface, we need to add validation controls to the (Click to view full-size image) All validation controls work by validating the input of a single ASP. Therefore, we need to indicate that the Required Field Validator we just added should validate against the Text Box in the property value is also the text displayed by the validation control on invalid input.You'll find that the appearance and behavior of the Template Fields is identical to the experience when Bound Fields were used instead.When constructing data entry forms, it is important that users enter any required fields and that all provided inputs are legal, properly-formatted values.