Chapter 8. Gathering Data with ASP.NET Web Forms

only for RuBoard
  • Button ASP.NET Server Control

  • TextBox ASP.NET Server Control

  • DropDownList ASP.NET Server Control

  • ListBox ASP.NET Server Control

  • CheckBox ASP.NET Server Control

  • CheckBoxList ASP.NET Server Control

  • RadioButton ASP.NET Server Control

  • RadioButtonList ASP.NET Server Control

  • Summary

Up to this point in the book we have discussed a number of ways to retrieve and show data using ASP.NET, but haven't touched on how to collect data from users and return it back to the server. We use a combination of a FORM ( <form runat ="server"> ) and controls to collect data from the user . A FORM is essentially a container that provides a way to exchange data between the client and server. ASP.NET comes with a rich collection of useful controls you can use within a FORM that makes data collection a very speedy and reliable process.

This chapter will discuss some of the more commonly used server controls ”be careful not to confuse these with HTML server controls, which also can collect data from users. Specifically, in this chapter we will cover the following ASP.NET server controls:

  • Button

  • TextBox

  • DropDownList

  • ListBox

  • CheckBox

  • CheckBoxList

  • RadioButton

  • RadioButtonList

We will be going over each of the proceeding server controls in some detail. We'll explain how to raise and handle some of the controls events, how to retrieve attributes from the control programmatically on the server, and, finally, we'll demonstrate how to bind the control to a data source, if applicable .

As you may or may not know, an ASP.NET server control that has a user interface doesn't render any special objects to the client (browser). If you were to view the source code sent to the client's browser you would see only a collection of HTML elements. For instance, there is a Calendar server control available to you right out of the box when you install .NET. When you drop this control into your web form and a client requests the page, a calendar is not rendered in the client's browser; instead, a mix of HTML elements is rendered that looks like a calendar. My point is, every server control has an HTML counterpart . In some of the sections of this chapter I'll demonstrate this fact by showing you both the server control code and the code that is actually sent to the client. I recommend viewing source on all new controls you use so you become famililar with what HTML is actually sent to the client.

Typically when gathering information or data from users you must validate the data they give you. For instance, if you have a field in your form where the user must enter their date of birth, you probably want to make sure that they enter a valid date. In this chapter we will not be validating the data collected. In Chapter 9, "Evaluating Data with ASP.NET Validation Controls," we'll discuss using the ASP.NET validation controls to validate data. Validation controls are server controls that can be wired or bound to other controls and automatically validate their values.

only for RuBoard


Programming Data-Driven Web Applications with ASP. NET
Programming Data-Driven Web Applications with ASP.NET
ISBN: 0672321068
EAN: 2147483647
Year: 2000
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net