Introduction to Forms


Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Day 5.  Beginning Web Forms

Let's take a look again at how the Web works. Recall from Day 1, "Getting Started with ASP.NET," that a client sends a request to a server for some information, and the server responds by sending the appropriate file. This is the basis of the request/response model.

The client can also send data to the server. HTML forms allow user interaction with Web pages they provide communication between the client and server. For example, Listing 5.1 displays a typical HTML form that allows the user to enter his name and click a Submit button.

Listing 5.1 A Typical HTML Form
 1:    <html><body> 2:       <form method="post"> 3:          Please enter your name: 4:          <input type="text" size="20"> 5:          <input type="Submit" value="Submit"> 6:      </form> 7:    </body></html> 

When the user clicks the Submit button, the form posts to the server any data that the user has entered. This is similar to a client request, but the browser sends additional information along with the post that the server can use for its purposes. HTML forms consist of elements that make up a user interface. They're completely client-based. Users enter data into these elements and submit the form, which posts the data to the server. Figure 5.1 illustrates this concept.

Figure 5.1. The server receives only the information that the user enters.


Other than a post and a request, there's no way for the server to communicate with the client. Thus, all Web-based applications must rely on this model, making programming sometimes difficult. With such sparse communication between client and server, it's difficult for either one to gather much information about the other. For instance, the server won't know the capabilities of the client browser or what it's trying to do, making the client's behavior completely unpredictable.

The server also has no idea what the user interface looks like or what kind of data it should expect once the form is posted. All the server knows is what the form tells it, which usually isn't very much. As soon as the post is finished, the server forgets everything the form told it and it loses track of what's going on.


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne © 2008-2017.
    If you may any questions please contact us: