Deitel & Associates, Inc. Logo

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

ISBN:
0-13-152523-9
© 2006
pages: 1535

Order
Amazon logo

This is the fourth in a series of four tutorials that introduces ASP.NET 2.0 and Microsoft's Visual Web Developer Express IDE for building Web applications. The Visual Web Developer Express functionality we discuss is also part of the complete Visual Studio 2005. Both Visual Web Developer Express and Visual Studio 2005 were released in November 2005. This series of tutorials is a small part of Chapter 21, ASP.NET, Web Forms and Web Conrols, from our book Visual C# 2005 How to Program, 2/e. Chapter 21 is part of a four chapter sequence on XML, ADO.NET, ASP.NET and Web Services in which we discuss each of these technologies and demonstrate how to build substantial, data driven Web applications.

Part 1 provided a brief introduction to ASP.NET, Web Forms and Web controls. Part 2 discussed simple HTTP transactions that enable client/server interactions on the Web. Part 3 overviewed multitier application architecture. This part (which consists of several subsections that you can link to at the bottom of this page) presents a simple Web Form example, analyzes its parts, shows how it executes, and discusses how to build and deploy the Web Form. The tutorials in this series are intended for students and professionals who are already familiar with Visual C# programming.

[Note: This series of tutorials is an excerpt (Sections 21.1-21.4) of Chapter 21, ASP.NET, Web Forms and Web Controls (pp. 1051-1070), from our textbook Visual C# 2005 How to Program, 2/e. These tutorials may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., Visual C# 2005 How to Program, 2/e 2005. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]

Download the Code Examples for this Tutorial
21.4   Creating and Running a Simple Web-Form Example
Our first example displays the Web server's time of day in a browser window. When run, this program displays the text A Simple Web Form Example, followed by the Web server's time. As mentioned previously, the program consists of two related files-an ASPX file (Fig. 21.4) and a C# code-behind file (Fig. 21.5). We first display the markup, code and output, then we carefully guide you through the step-by-step process of creating this program. [Note: The markup in Fig. 21.4 and other ASPX file listings in this chapter is the
Fig. 21.4 ASPX file that displays the Web server's time. 
1   <%-- Fig. 21.4: WebTime.aspx --%>
2   <%-- A page that displays the current time in a Label. --%>
3   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebTime.aspx.cs"
4      Inherits="WebTime" EnableSessionState="False" %>
5   
6   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
7      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
8   
9   <html xmlns="http://www.w3.org/1999/xhtml">
10     <head runat="server">
11        <title>A Simple Web Form Example</title>
12     </head>
13     <body>
14        <form id="form1" runat="server">
15           <div>
16              <h2>Current time on the Web server:</h2>
17              <p>
18                 <asp:Label ID="timeLabel" runat="server" BackColor="Black"
19                    Font-Size="XX-Large" ForeColor="Yellow"
20                    EnableViewState="False"></asp:Label>
21              </p>
22           </div>
23        </form>
24     </body>
25  </html>
same as the markup that appears in Visual Web Developer, but we have reformatted the markup for presentation purposes to make the code more readable.]
Visual Web Developer generates all the markup shown in Fig. 21.4 when you set the Web page's title, type text in the Web Form, drag a Label onto the Web Form and set the properties of the page's text and the Label. We show these steps shortly.
 
Continue to Examining an ASPX File

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