So far we have seen only one Web control that is used to gather user input, the TextBox Web control. As we have seen in the examples thus far in the book, the TextBox Web control presents users with a text box into which they can type their input. For example, in the monthly mortgage cost calculator in Hour 4, "Designing, Creating, and Testing ASP.NET Pages," the user inputted the amount, duration, and interest rate of a mortgage to determine its monthly cost. In the BMI Calculator in Hour 9, "Web Form Basics," the user supplied his height and weight in text boxes. Additionally, there was a plethora of TextBox Web control examples in the preceding hour. Text boxes, however, are not the only means by which user input can be collected. As we will see in this hour, other input collection Web controls include the DropDownList Web control, the CheckBox Web control, and the RadioButton Web control. The DropDownList Web control presents users with a list of options, from which they may choose one. The CheckBox Web control presents users with a box that can be ticked or cleared to indicate a yes or no type answer. The RadioButton Web control presents users with a single, selectable option. Typically, a series of RadioButton controls are used, each displaying a single option from which the visitor can select only one of the available choices. Given that there are a number of Web controls designed to collect user input, you may be wondering when you should use a TextBox Web control versus an alternative Web control. The type of Web control should be determined by the kind of input that is being collected. The input collected from users can be classified into various types. The following classifications group input in terms of their restrictiveness, from the most restrictive form of input, to the least:
The first classification, Yes/No input, is input that can be inputted in only one of two ways. For example, an online survey may ask you for your gender, which can be only one of two values, Male or Female. A slightly more general input classification is input selected from a list of acceptable choices. If you live in the United States and are filling out your address on an online form, the state you live in can be selected from a finite list of the 50 states. Another example of input that falls into this category is a list of shipping options that an eCommerce site might provide for you to select from. General text input is the most lax of the three categories. Input that falls into this category includes filling in your name and address on an online form or entering your message on an online messageboard site. Using an Appropriate Web ControlWhen collecting user input, you must decide what Web control to use. For example, if you are asking users to specify their gender, you could use a TextBox Web control, asking users to type in whether they are Male or Female. However, this approach lends itself to user error. A visitor may misspell Female or type in Woman instead. A less error-prone approach would be to use a DropDownList Web control with two options: Male or Female. Other Yes/No inputs work well with check boxes. For example, many websites require you to create an account to access certain portions of the site. When filling in the account information, you will typically find a check box labeled something like Send Me the Site Newsletter or Keep Me Abreast of New Products from Your Company. In this same account creation page, users may be prompted to specify how they learned about the website. Rather than requiring users to type in an explanation, many websites will provide a drop-down list that contains a number of potential choices, such as Read About It in Print, Heard About It from a Friend, and so on. A series of radio buttons would also work here.
Input that falls into the general text input category, such as a person's name or mailing address, must be entered via TextBox Web controls. The point of this discussion is to highlight that there are different classes of user input, and different Web controls work best with different classes of user input. Keep this in mind while you're learning about the DropDownList, CheckBox, and RadioButton Web controls in this hour. Table 11.1 summarizes the classifications of user input and what types of Web controls work best.
|