An ASP.NET Web Application in Action
(Page 1 of 5 )
In this conclusion to a three-part series on ASP.Net web programming, you'll take a look at how an ASP.Net application actually works. This article is excerpted from chapter one of
Murach's ASP.NET 3.5 Web Programming with VB 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774472).
A quick preview of how an ASP.NET application works
With that as background, you’re ready to learn more about how an ASP.NET application works. That’s why this topic presents a quick preview of how the Order form in the Shopping Cart application works.
The files used by the Shopping Cart application
Figure 1-9 presents the Order form of the Shopping Cart application as it appears in the Web Forms Designer that you use when you develop web forms with Visual Studio 2008. In chapter 2, you’ll learn how to use this Designer, but for now just try to get the big picture of how this form works.
If you look at the Designer window in the middle of the IDE, you can see the table that’s used for this form as well as the label controls that are used to display the data for each product. You can also see that the smart tag menu for the drop-down list has been used to enable the AutoPostBack property. This means that the Order form will be posted back to the web server when the user selects an item from the drop-down list.
If you look at the Solution Explorer to the right of the Designer window, you can see the folders and files that this application requires. For now, though, just focus on the six code files that are summarized in the table in this figure. The first two files in this table, which are in the App_Code folder, are two files that represent business classes named CartItem and Product. Both of these files have vb as the extension, which means that they’re Visual Basic files.
The next four files in the table are for the two web forms, Cart and Order, with two files for each form. The files with aspx as the extension (Cart.aspx and Order.aspx) contain the code that represents the design of the form. This code consists of standard HTML code plus asp tags that define the server controls used on the forms. We refer to this as aspx code, because the files that contain the code have the aspx extension.
The other two files, which have aspx.vb as the extension, contain the Visual Basic code that controls the operation of the forms. These are called code-behind files because they provide the code behind the web forms. For instance, the Order.aspx.vb file is the code-behind file for the Order form.
Before I go on, you should realize that it isn’t necessary to store the aspx and Visual Basic code for a web form in separate files. Instead, ASP.NET lets you combine this code into a single aspx file. However, storing the aspx and Visual Basic code in separate files can simplify application development because it lets you separate the presentation elements for a page from its Visual Basic coding. This also makes it possible for HTML designers to work on the aspx files for an application, and then have Visual Basic programmers develop the code for the code-behind files.
The Order form in Design view

The aspx and Visual Basic files in the Shopping Cart application
| Folder File | Description |
|---|
| App_Code | CartItem.vb | A class that represents an item in the shopping cart. |
| App_Code | Product.vb | A class that represents a product. |
| (root) | Cart.aspx | The aspx file for the Cart page. |
| (root) | Cart.aspx.vb | The code-behind file for the Cart page. |
| (root) | Order.aspx | The aspx file for the Order page. |
| (root) | Order.aspx.vb | The code-behind file for the Order page. |
Description
For each web form in an application, ASP.NET 3.5 keeps two files. The file with the aspx extension holds the HTML code and the asp tags for the server controls. The file with the aspx.vb extension is the code-behind file that contains the Visual Basic code for the form.
If an ASP.NET 3.5 application requires other classes like business classes, they are kept in the App_Code folder.
Figure 1-9 The files used by the Shopping Cart application
Next: The aspx code for the Order form >>
More ASP.NET Articles
More By Murach Publishing
|
This article is an excerpt from chapter one of Murach's ASP.NET 3.5 Web Programming with VB 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774472). Check it out today at your favorite bookstore. Buy this book now.
|
|