Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
Visual Basic 2005
How to Program, 3/e

ISBN:
0-13-186900-0
© 2005
pages: ~1500

Pre-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 are scheduled to be released in November 2005. This series of tutorials is a small part of Chapter 21, ASP.NET, Web Forms and Web Conrols, from our forthcoming book Visual Basic 2005 How to Program, 3/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 Basic .NET programming. These tutorials are intended for students and professionals who are already familiar with Visual Basic .NET programming.

[Note: This series of tutorials is an excerpt (Sections 21.1-21.4) of Chapter 21, ASP.NET, Web Forms and Web Controls, from our forthcoming textbook Visual Basic 2005 How to Program, 3/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 Basic 2005 How to Program, ©2005. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]

Part 4 Continued: 21.4.3 Relationship Between an ASPX File and a Code-Behind File
How are the ASPX and code-behind files used to create the Web page that is sent to the client? First, recall that class WebTime is the base class specified in line 3 of the ASPX file (Fig. 21.4). This class (partially declared in the code-behind file) inherits from Page, which defines the general functionality of a Web page. Partial class WebTime inherits this functionality and defines some of its own (i.e., displaying the current time). The code-behind file contains the code to display the time, whereas the ASPX file contains the code to define the GUI.
When a client requests an ASPX file, ASP.NET creates two classes behind the scenes. Recall that the code-behind file contains a partial class named WebTime. The first file ASP.NET generates is another partial class containing the remaining portion of class WebTime based on the markup in the ASPX file. For example, WebTime.aspx contains a Label Web control with ID timeLabel, so the generated partial class would contain a declaration for a Label variable named timeLabel. This partial class might look like
Partial Class WebTime
   Protected timeLabel As System.Web.UI.WebControls.Label
   End Class
Note that a Label is a Web control defined in namespace System.Web.UI.WebControls, which contains Web controls for designing a page's user interface. Web controls in this namespace derive from class WebControl. When compiled, this partial class declaration containing Web control declarations combines with the code-behind file's partial class declaration to form class WebTime. This explains why line 11 in method Page_Init of WebTime.aspx.vb (Fig. 21.5) can access timeLabel, which is created in lines 18-20 of WebTime.aspx (Fig. 21.4)-method Page_Init and control timeLabel are actually members of the same class, but defined in separate partial classes.
The second class generated by ASP.NET is a class based on the ASPX file that is used to create the visual aspect of the page. This new class inherits from class WebTime, which defines the logic of the page. The first time the Web page is requested, this class is compiled, and an instance is created. This instance represents our page-it creates the XHTML that is sent to the client. The assembly created from our compiled classes is placed within a subdirectory of
C:\WINDOWS\Microsoft.NET\Framework\VersionNumber\
   Temporary ASP.NET Files\WebTime

where VersionNumber is the version number of the .NET Framework (e.g., v2.0.50215) installed on your computer.
Performance Tip 21.1
Once an instance of the Web page has been created, multiple clients can use it to access the page-no recompilation is necessary. The project will be recompiled only when you modify the application; changes are detected by the runtime environment, and the project is recompiled to reflect the altered content.

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

Tutorial Index