Murach S: Web Programming With
Murach S: Web Programming With
murach’s
ASP.NET 2.0
web programming with
VB 2005
(Chapter 1)
Thanks for downloading this chapter from Murach’s ASP.NET 2.0 Web Programming
with VB 2005. We hope it will show you how easy it is to learn from any Murach book,
with its paired-pages presentation, its “how-to” headings, its practical coding examples,
and its clear, concise style.
To view the full table of contents for this book, you can go to our web site. From there,
you can read more about this book, you can find out about any additional downloads
that are available, and you can review our other books on .NET development.
Thanks for your interest in our books!
Section 1
1
An introduction to ASP.NET
web programming
This chapter introduces you to the basic concepts of web programming and
ASP.NET. Here, you’ll learn how web applications work and what software
you need for developing ASP.NET web applications. You’ll also see how the
HTML code for a web form is coordinated with the Visual Basic code that
makes the web form work the way you want it to. When you finish this chapter,
you’ll have the background you need for developing web applications of your
own.
Internet
Description
• Web applications are a type of client/server application. In that type of application, a
user at a client computer accesses an application at a server computer. In a web applica-
tion, the client and server computers are connected via the Internet or via an intranet (a
local area network).
• In a web application, the user works with a web browser at the client computer. The web
browser provides the user interface for the application. The most popular web browser is
Microsoft’s Internet Explorer, but other web browsers like Netscape Navigator or
Mozilla Firefox may also be used.
• The application runs on the server computer under the control of web server software.
For ASP.NET web applications, the server must run Microsoft’s web server, called
Internet Information Services, or IIS.
• For most web applications, the server computer also runs a database management
system, or DBMS, such as Microsoft’s SQL Server. The DBMS provides access to
information stored in a database. To improve performance on larger applications, the
DBMS can be run on a separate server computer.
• The user interface for a web application is implemented as a series of web pages that are
displayed in the web browser. Each web page is defined by a web form using HTML, or
Hypertext Markup Language, which is a standardized set of markup tags.
• The web browser and web server exchange information using HTTP, or Hypertext
Transfer Protocol.
Figure 1-2 The hardware and software components for web applications
8 Section 1 The essence of ASP.NET web programming
HTTP request
HTTP response
Description
• A static web page is an HTML document that is the same each time it’s viewed. In other
words, a static web page doesn’t change in response to user input. Everyone who views a
static web page sees exactly the same content.
• Static web pages are usually simple HTML files that are stored on the web server. When
a browser requests a static web page, the web server retrieves the file from disk and
sends it back to the browser. Static web pages usually have a file extension of .htm or
.html.
• A web browser requests a page from a web server by sending the server an HTTP
message known as an HTTP request. The HTTP request includes, among other things,
the name of the HTML file being requested and the Internet address of both the browser
and the web server.
• A user working with a browser can initiate an HTTP request in several ways. One way is
to type the address of a web page, called a URL, or Uniform Resource Locator, into the
browser’s address area and then press the Enter key. Another way is to click a link that
refers to a web page.
• A web server replies to an HTTP request by sending a message known as an HTTP
response back to the browser. The HTTP response contains the addresses of the browser
and the server as well as the HTML document that’s being returned.
HTTP request
Application
Web server
Browser server
(IIS)
(ASP.NET)
HTTP response
Web
application
forms
(.aspx)
Description
• A dynamic web page is an HTML document that’s generated by a web form. Often, the
web page changes according to information that’s sent to the web form by the browser.
• When a web server receives a request for a dynamic web page, it looks up the extension
of the requested file in a list of application mappings to find out which application server
should process the request. If the file extension is aspx, the request is passed on to
ASP.NET for processing.
• When the application server receives a request, it runs the specified web form. Then, the
web form generates an HTML document and returns it to the application server, which
passes it back to the web server and from there to the browser.
• The browser doesn’t know or care whether the HTML was retrieved from a static HTML
file or generated dynamically by a web form. Either way, the browser simply displays
the HTML that was returned as a result of the request.
• After the page is displayed, the user can interact with it using its controls. Some of those
controls let the user post the page back to the server, which is called a postback. Then,
the page is processed again using the data the user entered.
• The process that begins with the user requesting a web page and ends with the server
sending a response back to the client is called a round trip.
• If you omit the file name from the URL when you use your browser to request a page,
IIS will look for a file with one of four names by default: Default.htm, Default.asp,
index.htm, and iisstart.asp. If you want another page to be displayed by default, you can
add the name of that page to this list. See appendix A for more information.
Concepts
• State refers to the current status of the properties, variables, and other data maintained by
an application for a single user. The application must maintain a separate state for each
user currently accessing the application.
• HTTP is a stateless protocol. That means that it doesn’t keep track of state between
round trips. Once a browser makes a request and receives a response, the application
terminates and its state is lost.
Figure 1-6 The software you need for developing ASP.NET 2.0 applications
16 Section 1 The essence of ASP.NET web programming
.NET Applications
.NET Framework
Description
• .NET applications work by using services of the .NET Framework. The .NET Frame-
work, in turn, accesses the operating system and computer hardware.
• The .NET Framework consists of two main components: the .NET Framework Class
Library and the Common Language Runtime.
• The .NET Framework Class Library provides pre-written code in the form of classes that
are available to all of the .NET programming languages. These classes are organized into
groups called namespaces. The classes that support ASP.NET web programs are stored
in the System.Web namespace.
• The Common Language Runtime, or CLR, manages the execution of .NET programs by
coordinating essential functions such as memory management, code execution, security,
and other services.
• The Common Type System is a component of the CLR that ensures that all .NET applica-
tions use the same data types regardless of what programming languages are used to
develop the applications.
• All .NET programs are compiled into Microsoft Intermediate Language (MSIL) or just
Intermediate Language (IL), which is stored on disk in an assembly. This assembly is
then run by the CLR.
Standalone development
Windows 2000 or later
.NET Framework 2.0
Visual Studio 2005
Optional: IIS, SQL Server
Internet development
Windows 2000 or later Windows 2000 Server or later
.NET Framework 2.0 .NET Framework
Visual Studio 2005 IIS 5.0 or later (6.0 recommended)
FTP server
Internet SQL Server
connection
Client Server
Description
• When you use standalone development, a single computer serves as both the client and
the server. Because Visual Studio comes with a scaled-back web server called the
ASP.NET Development Server (or just development server), you don’t need to use IIS
for testing web applications on your own PC. However, you do need to use IIS to test
certain features of web applications.
• When you use a local area network (LAN), a client computer communicates with a
server computer over the LAN. With this setup, two or more programmers at the same
site can work on the same application. This setup requires that FrontPage Server Exten-
sions (FPSE) be installed on the server.
• When you use Internet development, a client computer communicates with a server
computer over the Internet. With this setup, programmers at different locations can work
on the same application. This setup requires an FTP server on the server. The FTP server
uses File Transfer Protocol (FTP) to transfer files between the client computer and the
server.
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 2.0 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 2.0 application requires other classes like business classes, they are kept
in the App_Code folder.
Figure 1-11 The Visual Basic code for the Order form
26 Section 1 The essence of ASP.NET web programming
Code-behind file
Web form Order
(partial class) Class files in
App_Code folder
ASP.NET runtime
4
2 Compiler
Order Order
Order_aspx
(partial class) Compiler class
(dll)
Order.aspx Other
Compiler class classes
(dll) (dll)
Description
• The first four steps of this process are done only the first time the aspx page is requested.
After that, the page is processed directly from the compiled assemblies.
• For the Default page, the name of the code-behind class is _Default.
Perspective
Now that you’ve read this chapter, you should have a general understanding of
how ASP.NET applications work and what software you need for developing these
applications. With that as background, you’re ready to learn how to develop
ASP.NET applications of your own. And that’s what you’ll learn how to do in the
next two chapters.
Terms