Deitel & Associates, Inc. Logo

Back to
digg.png delicious.png blinkit.png furl.png
Visual C# 2005 How to Program, 2/e
Visual C# 2005 How to Program, 2/e

© 2006
pages: 1535

Amazon logo

Part 4 Continued: 21.4.5  Examining the XHTML Generated by an ASP.NET Application
Figure 21.6 shows the XHTML generated by ASP.NET when WebTime.aspx (Fig. 21.4) is requested by a client Web browser. To view this XHTML, select View > Source in Internet Explorer. [Note: We added the XHTML comments in lines 1-2 and reformatted the XHTML to conform to our coding conventions.]
The contents of this page are similar to those of the ASPX file. Lines 7-9 define a document header comparable to that in Fig. 21.4. Lines 10-28 define the body of the
Fig. 21.6 XHTML response when the browser requests WebTime.aspx
1   <!-- Fig. 21.6: WebTime.html -->
2   <!-- The XHTML generated when WebTime.aspx is loaded. -->
3   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
4      "">
6   <html xmlns="">
7      <head>
8         <title>A Simple Web Form Example</title>
9      </head>
10     <body>
11        <form method="post" action="WebTime.aspx" id="form1">
12           <div>
13              <input type="hidden" name="__VIEWSTATE"
14                 id="__VIEWSTATE" value=
15                 "/wEPDwUJODExMDE5NzY5ZGQ4n4mht8D7Eqxn73tM5LDnstPlCg==" />
16           </div>
18           <div>
19              <h2>Current time on the Web server:</h2>
20              <p>
21                 <span id="timeLabel" style="color:Yellow;
22                    background-color:Black;font-size:XX-Large;">
23                    17:13:52
24                 </span>
25              </p>
26           </div>
27        </form>
28     </body>
29  </html>
document. Line 11 begins the form, a mechanism for collecting user information and sending it to the Web server. In this particular program, the user does not submit data to the Web server for processing; however, processing user data is a crucial part of many applications that is facilitated by the form. We demonstrate how to submit data to the server in later examples.
XHTML forms can contain visual and nonvisual components. Visual components include clickable buttons and other GUI components with which users interact. Nonvisual components, called hidden inputs, store data, such as e-mail addresses, that the document author specifies. One of these hidden inputs is defined in lines 13-15. We discuss the precise meaning of this hidden input later in the chapter. Attribute method of the form element (line 11) specifies the method by which the Web browser submits the form to the server. The action attribute identifies the name and location of the resource that will be requested when this form is submitted-in this case, WebTime.aspx. Recall that the ASPX file's form element contained the runat="server" attribute-value pair (line 14 of Fig. 21.4). When the form is processed on the server, the runat attribute is removed. The method and action attributes are added, and the resulting XHTML form is sent to the client browser.
In the ASPX file, the form's Label (i.e., timeLabel) is a Web control. Here, we are viewing the XHTML created by our application, so the form contains a span element (lines 21-24 of Fig. 21.6) to represent the text in the label. In this particular case, ASP.NET maps the Label Web control to an XHTML span element. The formatting options that were specified as properties of timeLabel, such as the font size and color of the text in the Label, are now specified in the style attribute of the span element.
Notice that only those elements in the ASPX file marked with the runat="server" attribute-value pair or specified as Web controls are modified or replaced when the file is processed by the server. The pure XHTML elements, such as the h2 in line 19, are sent to the browser exactly as they appear in the ASPX file.
Building an ASP.NET Web Application

Tutorials in This Series:
ASP.NET Tutorial Part 1: Introduction to ASP.NET
ASP.NET Tutorial Part 2: Simple HTTP Transactions
ASP.NET Tutorial Part 3: Multitier Application Architecture
ASP.NET Tutorial Part 4: Creating and Running a Simple Web Form Example (You are here.)

Tutorial Index