Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
In ASP.NET input, validation is performed through the use ofyou guessed itWeb controls. The Web controls that perform input validation are commonly called validation Web controls, or just validation controls. We'll be examining four kinds of validation controls in this hour, which are summarized in Table 12.1. Each of these Web controls is geared for providing one or more of the input validation classes discussed in the preceding sections.
In the following sections, we will examine each of these validation Web controls in detail. Specifically, we will look at how to add these Web controls to an ASP.NET page, how to specify what user input they are to validate, and how to determine whether the user's input meets the required validation. After examining each of these four Web controls individually, we will see how to use multiple validation controls on a single ASP.NET page. An ASP.NET Web Page for Examining the Validation Controls
Before examining how to use these validation controls, let's first create an ASP.NET web page that we can use throughout all of these exercises. Specifically, we will create an ASP.NET page that collects the following information from users:
Now that we've added the needed TextBox Web controls, let's set the ID properties for these TextBox Web controls. Set the first TextBox Web control's ID property to name; the second's to age; the third's to ssn; the fourth's to totalChildren; and the fifth's to maleChildren. For the age, totalChildren, and maleChildren TextBox Web controls, also set the Columns property to 4. Next, add a Button Web control after the five TextBox Web controls. Set this Web control's ID property to btnSubmit and its Text property to Click Me. Finally, add a Label Web control with ID results below the Button Web control. Your screen should now look similar to Figure 12.2. Figure 12.2. The TextBox Web controls have had their properties set, and a Button Web control has been added.
At this point, you may want to test the ValidationControlTestBed.aspx ASP.NET page (you can see this page in Figure 12.7). When you visit the ASP.NET page via a browser, go ahead and enter some test information into the various text boxes. Naturally, there is no input validation, meaning you can enter nonsensical text into any of these text boxes.
Now that we have created the ASP.NET web page to which we will add the various ASP.NET validation controls, we are ready to begin our examination of these controls, starting with the RequiredFieldValidator Web control. |
Категории