In this hour we examined how user input can be collected in an ASP.NET web page. We started by examining the HTML elements needed to collect user input, which include a number of <input> elements for each text box, check box, radio button, or drop-down list; and a <form> element, inside which the <input> elements must be enclosed. Additionally, a submit button is needed. With ASP.NET web pages, we do not need to worry about creating these HTML elements by hand. Rather, we can simply use appropriate Web controls, such as the TextBox Web control for displaying a text box, a CheckBox Web control for displaying a check box, and so on. To collect a user's input, these Web controls must be placed inside a Web Form. A Web Form, as we saw, is a Web control of the form, as follows: <form runat="server"> ... </form> Visual Web Developer automatically enters a Web Form when creating a new ASP.NET page. In addition to the Web controls needed to collect the user's input, a Button Web control should be added in the Web Form. The Button Web control is rendered as a submit button that, when clicked, submits the form, performing a postback. If you have source code that you want to execute whenever the Web Form is submitted, you can place it in the Button Web control's Click event handler. To add a Click event handler to your ASP.NET web page, simply double-click the Button Web control from the Design view. Now that we have seen how an ASP.NET page can collect user input and perform calculations on this input, we're ready to examine the Web controls for collecting user input in much finer detail. In the next hour we'll focus on examining the TextBox Web control. Following that hour, we'll look at collecting a user's input using the DropDownList, RadioButton, and CheckBox Web controls. |