Tải bản đầy đủ (.pdf) (645 trang)

Tài liệu Sams Teach Yourself ASP.NET 4 in 24 Hours ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.26 MB, 645 trang )

ptg
www.it-ebooks.info
ptg
800 East 96th Street, Indianapolis, Indiana, 46240 USA
Scott Mitchell
Sams Teach Yourself
24
in
Hours
ASP.NET 4
Complete Starter Kit
www.it-ebooks.info
ptg
Sams Teach Yourself ASP.NET 4 in 24 Hours, Complete Starter Kit
Copyright © 2010 by Pearson Education, Inc.
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or
transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without
written permission from the publisher. No patent liability is assumed with respect to the use of
the information contained herein. Although every precaution has been taken in the preparation of
this book, the publisher and author assume no responsibility for errors or omissions. Nor is any
liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-672-33305-7
ISBN-10: 0-672-33305-8
Library of Congress Cataloging-in-Publication Data:
Mitchell, Scott, 1978-
Sams teach yourself ASP.NET 4 in 24 hours complete starter kit / Scott Mitchell. — 1st ed.
p. cm.
Includes bibliographical references and index.
ISBN 978-0-672-33305-7 (alk. paper)
1. Active server pages. 2. Microsoft .NET. 3. Web sites—Design. I. Title. II. Title: Teach
yourself ASP.NET 4 in 24 hours complete starter kit. III. Title: ASP.NET 4 in 24 hours complete


starter kit.
TK5105.8885.A26M585 2010
006.7’882—dc22
2010016855
Printed in the United States of America
First Printing June 2010
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been
appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use
of a term in this book should not be regarded as affecting the validity of any trademark or service
mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no
warranty or fitness is implied. The information provided is on an “as is” basis. The author and the
publisher shall have neither liability nor responsibility to any person or entity with respect to any
loss or damages arising from the information contained in this book or from the use of the CD or
programs accompanying it.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk pur-
chases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419

For sales outside of the U.S., please contact
International Sales

Editor-in-Chief
Karen Gettman
Executive Editor
Neil Rowe

Development
Editor
Mark Renfrow
Managing Editor
Kristy Hart
Project Editor
Lori Lyons
Copy Editor
Bart Reed
Indexer
Brad Herriman
Proofreader
Kay Hoskin
Technical Editor
Eric Weinberger
Publishing
Coordinator
Cindy Teeters
Multimedia
Developer
Dan Scherf
Book Designer
Gary Adair
Compositor
Nonie Ratcliff
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Contents at a Glance
Introduction. 1

Part I: Getting Started with ASP.NET 4
HOUR 1 Getting Started with ASP.NET 4 7
2 Understanding the ASP.NET Programming Model . 25
3 Using Visual Web Developer 57
4 Designing, Creating, and Testing ASP.NET Pages . 73
5 Understanding Visual Basic’s Variables and Operators 101
6 Managing Program Flow with Visual Basic’s Control Structures. 121
7 Working with Objects in Visual Basic . 147
8 ASP.NET Web Controls for Displaying Text 157
Part II: Collecting and Processing User Input
HOUR 9 Web Form Basics 179
10 Using Text Boxes to Collect Input . 201
11 Collecting Input Using Drop-Down Lists, Radio Buttons,
and Checkboxes 221
12 Validating User Input with Validation Controls 247
Part III: Working with Databases
HOUR 13 Introducing Databases . 283
14 Accessing Data with the Data Source Web Controls. 305
15 Displaying Data with the Data Web Controls. 333
16 Deleting, Inserting, and Editing Data . 359
17 Working with Data-Bound DropDownLists, Radio Buttons,
and CheckBoxes 393
18 Exploring Data Binding and Other Data-Related Topics. 415
19 Using Templated Data Web Controls . 441
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Part IV: Site Navigation, User Management, Page Layout, AJAX, and
Deployment
HOUR 20 Defining a Site Map and Providing Site Navigation. 469

21 Using Master Pages to Provide Sitewide Page Templates . 495
22 Managing Your Site’s Users 521
23 Building More Responsive Web Pages with ASP.NET AJAX 555
24 Deploying Your Website 573
Index . 595
iv
Teach Yourself ASP.NET 4 in 24 Hours
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Table of Contents
Introduction 1
Part I: Getting Started with ASP.NET 4
HOUR 1: Getting Started with ASP.NET 4 7
What Is ASP.NET? 8
Installing the .NET Framework, Visual Web Developer,
and SQL Server 2008 . 14
A Brief Tour of Visual Web Developer . 16
Q&A 23
Workshop 24
HOUR 2: Understanding the ASP.NET Programming Model
25
Examining the HTML Portion of an ASP.NET Page . 25
Examining the Source Code Portion of an ASP.NET Page 44
Q&A 53
Workshop 53
HOUR 3: Using Visual Web Developer
57
Creating a New Website . 58
Opening Existing Websites . 60

Working with Web Pages and Other Content . 61
Customizing the Visual Web Developer Experience . 65
Viewing, Moving, and Resizing Windows . 68
A World of Help at Your Fingertips . 69
Q&A . 70
Workshop . 71
From the Library of Wow! eBook
www.it-ebooks.info
ptg
HOUR 4: Designing, Creating, and Testing ASP.NET Pages 73
Specifying the Design Requirements . 73
Creating the User Interface 76
Writing the Source Code for the ASP.NET Page . 82
Testing the Financial Calculator . 86
Examining the Source Code 92
Using the Debugger 93
Q&A 97
Workshop 98
HOUR 5: Understanding Visual Basic’s Variables and Operators
101
The Purpose of Programming Languages 102
Declaring and Using Variables 103
Examining Visual Basic’s Operators . 110
Learning Visual Basic’s Type Rules . 116
Q&A . 118
Workshop . 118
HOUR 6: Managing Program Flow with Visual Basic’s Control Structures
121
Understanding Control Structures . 122
Exploring the Conditional Control Structure . 123

Working with Visual Basic’s Looping Control Structures . 128
Exploring the Modularizing Control Structures:
Subroutines and Functions 131
Q&A . 142
Workshop . 144
HOUR 7: Working with Objects in Visual Basic
147
Reexamining the Role of Classes and Objects . 148
Creating an Object . 150
Setting an Object’s Properties . 151
Calling an Object’s Methods . 152
Creating Event Handlers for an Object’s Events . 153
Q&A . 155
Workshop . 155
vi
Teach Yourself ASP.NET 4 in 24 Hours
From the Library of Wow! eBook
www.it-ebooks.info
ptg
HOUR 8: ASP.NET Web Controls for Displaying Text 157
Examining the Web Controls Designed for Displaying Text . 157
Using the Literal Web Control . 158
Using the Label Web Control . 163
Q&A . 172
Workshop . 173
Part II: Collecting and Processing User Input
HOUR 9: Web Form Basics 179
Gathering User Input in an HTML Web Page . 180
Dissecting ASP.NET Web Forms 186
Q&A . 198

Workshop . 199
HOUR 10: Using Text Boxes to Collect Input
201
Learning About the TextBox Web Control Basics 202
Creating Multiline and Password Text Boxes. 205
Examining the TextBox Web Control’s Properties 211
Q&A . 216
Workshop . 218
HOUR 11: Collecting Input Using Drop-Down Lists, Radio Buttons,
and Check Boxes 221
Examining the Different Types of User Input Classifications 222
Examining the DropDownList Web Control . 224
Selecting One Option from a List of Suitable Choices with
RadioButton Web Controls 233
Using the CheckBox Web Control 238
Q&A . 243
Workshop . 244
HOUR 12: Validating User Input with Validation Controls
247
Examining the Need for User Input Validation . 248
Validating User Input in an ASP.NET Page . 250
Contents
vii
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Examining the RequiredFieldValidator Validation Control . 253
Examining the CompareValidator. 261
Using the RangeValidator . 268
Validating Input with the RegularExpressionValidator . 269

Formatting Properties for the Validation Web Controls . 272
A Look at the Remaining Validation Controls . 274
Q&A . 276
Workshop . 277
Part III: Working with Databases
HOUR 13: Introducing Databases 283
Examining Database Fundamentals . 284
Storing Structured Data 285
Creating a New Database 290
Creating Database Tables 292
Adding Data to the Books Table . 298
Q&A . 302
Workshop . 303
HOUR 14: Accessing Data with the Data Source Web Controls
305
Examining the Data Source Controls. 306
A Look at SQL, the Language of Databases . 314
Delving into the SQL SELECT Statement. 314
Filtering and Sorting Data from the SqlDataSource Control’s Wizard . 323
Q&A . 330
Workshop . 331
HOUR 15: Displaying Data with the Data Web Controls
333
An Overview of Data Web Controls. 333
Displaying Data with the GridView Control . 337
Showing One Record at a Time with the DetailsView . 347
viii
Teach Yourself ASP.NET 4 in 24 Hours
From the Library of Wow! eBook
www.it-ebooks.info

ptg
Contents
ix
Paging and Sorting with the GridView 351
Q&A . 356
Workshop . 357
HOUR 16: Deleting, Inserting, and Editing Data
359
Updating, Deleting, and Inserting Data with the SqlDataSource . 360
Looking at the Data-Modification SQL Statements. 363
Editing and Deleting Data with the GridView . 366
Inserting Data with the DetailsView . 385
Q&A . 388
Workshop . 388
HOUR 17: Working with Data-Bound DropDownLists, RadioButtons,
and CheckBoxes 393
An Overview of the List Web Controls 394
Filtering Results Using the DropDownList 401
Collecting User Input with CheckBoxLists and RadioButtonLists 406
Q&A . 412
Workshop . 412
HOUR 18: Exploring Data Binding and Other Data-Related Topics
415
Looking at the GridView and DetailsView’s Fields . 416
Using Wildcards in a WHERE Filter Expression . 426
An Examination of Data Binding 429
Q&A . 436
Workshop . 438
HOUR 19: Using Templated Data Web Controls
441

Displaying Data Using the ListView Control . 442
Paging and Sorting the ListView’s Data . 450
Displaying One Record at a Time with the FormView Control . 456
Q&A . 463
Workshop . 464
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Part IV: Site Navigation, User Management, Page Layout, AJAX,
and Deployment
HOUR 20: Defining a Site Map and Providing Site Navigation 469
An Overview of ASP.NET’s Site-Navigation Features . 470
Defining the Website’s Structure Using a Site Map . 471
Displaying a Breadcrumb with the SiteMapPath Control . 476
Showing the Entire Site Structure 481
Q&A . 492
Workshop . 493
HOUR 21: Using Master Pages to Provide Sitewide Page Templates
495
An Overview of Master Pages. 496
Creating a Master Page 500
Creating a Content Page . 507
Providing Default Content in a Master Page . 510
Working with a Master Page’s Source Code Portion . 513
Q&A . 517
Workshop . 517
HOUR 22: Managing Your Site’s Users
521
An Overview of User Accounts in ASP.NET . 522
Allowing Visitors to Create New User Accounts . 533

Signing In to the Website with the Login Control 541
Displaying Content Based on Authentication Status 545
Examining the ASP.NET Web Site Template . 547
Q&A . 550
Workshop . 551
HOUR 23: Building More Responsive Web Pages with ASP.NET Ajax
555
An Overview of Ajax . 556
Using the ASP.NET Ajax Library . 558
Q&A . 568
Workshop . 569
x
Teach Yourself ASP.NET 4 in 24 Hours
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Contents
xi
HOUR 24: Deploying Your Website 573
Choosing a Web-Hosting Company. 574
Visiting the Remote Website . 590
Q&A . 592
Workshop . 593
Index
595
From the Library of Wow! eBook
www.it-ebooks.info
ptg
About the Author
As founder, editor, and main contributor of 4GuysFromRolla.com, a popular ASP.NET

resource website, Scott Mitchell has authored thousands of articles and tutorials on
Microsoft web technologies. In addition to his vast collection of online articles, Scott has
written seven previous books on ASP and ASP.NET: Sams Teach Yourself Active Server Pages 3.0
in 21 Days (Sams); Designing Active Server Pages (O’Reilly); ASP.NET: Tips, Tutorials, and Code
(Sams); ASP.NET Data Web Controls Kick Start (Sams); Teach Yourself ASP.NET in 24 Hours
(Sams); Teach Yourself ASP.NET 2.0 in 24 Hours (Sams); and Teach Yourself ASP.NET 3.5 in 24
Hours (Sams).
Scott’s regularly speaks at ASP.NET user groups and conferences across the country and
teaches classes on ASP.NET and related web technologies at the University of California—
San Diego University Extension. Scott also works as an independent software developer.
Scott can be reached at ; his blog is available at
www.ScottOnWriting.NET.
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Dedication
To Alice.
Acknowledgments
Writing a book is an arduous and draining endeavor, a feat that would not be possible
without the untiring patience and undying support of my wife and number one fan, Jisun.
You make life unbearably fun and full of smiles.
Thanks also to Neil Rowe, Mark Renfrow, Lori Lyons, Nonie Ratcliff, and the entire editorial
team at Sams Publishing.
From the Library of Wow! eBook
www.it-ebooks.info
ptg
We Want to Hear from You!
As the reader of this book, you are our most important critic and commentator. We value
your opinion and want to know what we’re doing right, what we could do better, what
areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass

our way.
You can email or write me directly to let me know what you did or didn’t like about this
book—as well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and
that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author as well as your name
and phone or email address. I will carefully review your comments and share them with the
author and editors who worked on the book.
E-mail:
Mail: Neil Rowe
Executive Editor
Sams Publishing
800 East 96th Street
Indianapolis, IN 46240 USA
Reader Services
Visit our website and register this book at informit.com/register for convenient access to any
updates, downloads, or errata that might be available for this book.
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Introduction
My first exposure to the World Wide Web came at college during the latter half of the
1990s. At the time, you had to be a hard-core computer programmer to build even
the most rudimentary website. Today, with technologies like Microsoft’s ASP.NET, cre-
ating powerful, data-driven, dynamic web applications couldn’t be easier. Over the
course of 24 hours you will see just how fun and easy it can be to build useful, real-
world websites using ASP.NET.
ASP.NET web applications are composed of individual ASP.NET web pages. As we will
see in numerous examples, these ASP.NET pages can display HTML, collect user
input, and interact with databases. ASP.NET pages contain a mix of both HTML

and source code. It is the source code of an ASP.NET page that allows for the more
advanced features, such as accessing data from a database, or sending an email. The
source code of an ASP.NET web page can be written in any one of a number of pro-
gramming languages. For this book we will be using Microsoft’s Visual Basic pro-
gramming language. Don’t worry if you’ve never programmed in Visual Basic, or
even if you have never programmed at all. Starting with Hour 5, “Understanding
Visual Basic’s Variables and Operators,” we spend three hours examining program-
ming language concepts and the Visual Basic syntax.
Visual Web Developer is a free development editor used to create and test ASP.NET
pages, and is included in this book’s accompanying CD. Visual Web Developer sim-
plifies creating both the HTML and source code portions of ASP.NET pages. The
HTML for an ASP.NET web page can be quickly created by using the Designer, which
is a What You See Is What You Get (WYSIWYG) graphical editor. With the Designer,
you can drag and drop various HTML elements onto an ASP.NET web page, moving
them around with a few clicks of the mouse. Likewise, Visual Web Developer offers
tools and shortcuts that help with creating an ASP.NET page’s code.
Audience and Organization
This book is geared for developers new to ASP.NET, whether or not you’ve had past
experience with HTML or programming languages. By the end of this book you’ll be
able to create and deploy your own dynamic, data-driven web applications using
ASP.NET.
This book’s 24 hours are divided into four parts. Part I introduces you to ASP.NET,
HTML, Visual Web Developer, and Visual Basic. Hour 1, “Getting Started with
From the Library of Wow! eBook
www.it-ebooks.info
ptg
2
Introduction
Did you
Know?

By the
Way
ASP.NET 4,” begins with an overview of ASP.NET and then walks you through
installing the .NET Framework, Visual Web Developer and other necessary compo-
nents. Hour 3, “Using Visual Web Developer,” showcases Visual Web Developer,
which is the powerful development editor you’ll be using throughout this book to cre-
ate ASP.NET web pages. Hours 5, 6, and 7 examine the syntax and semantics of the
Visual Basic programming language.
ASP.NET offers a variety of user interface elements for collecting user input, including
text boxes, check boxes, drop-down lists, and radio buttons. In Part II you will see
how to collect and process user input. Hour 10, “Using Text Boxes to Collect Input,”
examines using single-line, multi-line, and password text boxes, while Hour 11,
“Collecting Input Using Drop-Down Lists, Radio Buttons, and Check Boxes,” exam-
ines alternative user input controls.
Part III shows how easy it is to build data-driven websites with ASP.NET. Starting in
Hour 13, “Introducing Databases,” we begin our look at building websites that inter-
act with databases. Typically, data-driven websites enable visitors to view, update,
delete, and insert data into the database from an ASP.NET page. In Hour 15, “Dis-
playing Data with the Data Web Controls,” you will learn how to display database
data in a web page. Hour 16 examines how to edit, insert, and delete data.
Part IV highlights tools provided by ASP.NET and Visual Web Developer that help
with building professional, easy-to-use websites. In Hour 20, “Defining a Site Map
and Providing Site Navigation,” you’ll see how to define a website’s navigational
structure and display menus, treeviews, and breadcrumbs. Hour 21, “Using Master
Pages to Provide Sitewide Page Templates,” examines master pages, which enable
web designers to create a web page template that can be applied to all pages across
the site.
Conventions Used in This Book
This book uses several design elements and conventions to help you prioritize and
reference the information it contains:

By the Way boxes provide useful sidebar information that you can read immedi-
ately or circle back to without losing the flow of the topic at hand.
Did You Know? boxes highlight information that can make your Visual Basic pro-
gramming more effective.
From the Library of Wow! eBook
www.it-ebooks.info
ptg
Conventions Used in This Book
3
Watch
Out!
Watch Out! boxes focus your attention on problems or side effects that can occur
in specific situations.
New terms appear in a semibold typeface for emphasis.
In addition, this book uses various typefaces to help you distinguish code from regu-
lar English. Code is presented in a monospace font. Placeholders—words or characters
that represent the real words or characters you would type in code—appear in
italic monospace. Menu options are separated by a comma. For example, when
you should open the File menu and choose the New Project menu option, the text
says “Select File, New Project.”
Some code statements presented in this book are too long to appear on a single line.
In these cases, a line-continuation character ➥ is used to indicate that the following
line is a continuation of the current statement. Furthermore, some code listings
include line numbers. These numbers are used to refer to specific lines of code in the
text and are not part of the code syntax.
I hope you enjoy reading this book as much as I enjoyed writing it.
Happy Programming!
Scott Mitchell

From the Library of Wow! eBook

www.it-ebooks.info
ptg
This page intentionally left blank
From the Library of Wow! eBook
www.it-ebooks.info
ptg
[(H3F)]
5
PART I
Getting Started with
ASP.NET 4
HOUR 1 Getting Started with ASP.NET 4 7
HOUR 2 Understanding the ASP.NET Programming Model 25
HOUR 3 Using Visual Web Developer 57
HOUR 4 Designing, Creating, and Testing ASP.NET Pages 73
HOUR 5 Understanding Visual Basic’s Variables
and Operators 101
HOUR 6 Managing Program Flow with Visual Basic’s
Control Structures 121
HOUR 7 Working with Objects in Visual Basic 147
HOUR 8 ASP.NET Web Controls for Displaying Text 157
From the Library of Wow! eBook
www.it-ebooks.info
ptg
This page intentionally left blank
From the Library of Wow! eBook
www.it-ebooks.info
ptg
7
HOUR 1

Getting Started with
ASP.NET 4
In this hour, we will cover
.
What ASP.NET is
.
The system requirements for using ASP.NET
.
The software that must be installed prior to using ASP.NET
.
Installing the .NET Framework, Visual Web Developer, and SQL Server
2008
.
Taking a quick tour of Visual Web Developer
.
Creating a simple ASP.NET page and viewing it through a web browser
ASP.NET is an exciting web programming technology pioneered by Microsoft that
allows developers to create dynamic web pages. Dynamic web pages are pages
whose content is dynamically regenerated each time the web page is requested. For
example, after you sign in, the front page of Amazon.com shows recommended
products based on your previous purchases. This is a dynamic web page because it is
a single web page whose content is customized based on who is visiting. This book
explores how to create such dynamic web pages using ASP.NET.
ASP.NET is a robust and mature technology. ASP.NET version 1.0 was released in
January 2002 and quickly became the web programming technology of choice for
many. In November 2005, Microsoft released the much-anticipated version 2.0.
Two years later, in November 2007, Microsoft released ASP.NET version 3.5. And
ASP.NET 4 was unveiled in April 2010.
Before we create our first ASP.NET website, we need to install the .NET Framework,
Visual Web Developer, and SQL Server 2008. The .NET Framework is a rich platform

From the Library of Wow! eBook
www.it-ebooks.info
ptg
8
HOUR 1: Getting Started with ASP.NET 4
for creating Windows-based applications and is the underlying technology used to
create ASP.NET websites.
Visual Web Developer is a sophisticated program for creating, editing, and testing
ASP.NET websites and web pages. ASP.NET web pages are simple text files, meaning
that you can create them using any text editor (such as Microsoft Notepad), but if
you’ve created websites before, you know that using a tool such as Microsoft Expres-
sion Web or Adobe Dreamweaver makes the development process much easier than
using a generic text editor such as Notepad. This is the case for ASP.NET, as well.
SQL Server 2008 is a database engine, which is a specialized application designed to
efficiently store and query data. Many websites interact with databases; any ecom-
merce website, for example, displays product information and records purchase orders
in a database. Starting with Hour 13, “Introducing Databases,” we’ll see how to create,
query, and modify databases from an ASP.NET page.
This hour focuses on installing the necessary software so that we can start creating
ASP.NET web applications. We create a very simple ASP.NET page at the end of this
hour, but we won’t explore it in any detail. We look at ASP.NET pages in more detail
in the next hour and in Hour 4, “Designing, Creating, and Testing ASP.NET Pages.”
What Is ASP.NET?
Have you ever wondered how dynamic websites such as Amazon.com work behind
the scenes? As a shopper at Amazon.com, you are shown a particular web page, but
the web page’s content is dynamic, based on your preferences and actions. For
instance, if you have an account with Amazon.com, when you visit the home page
your name is shown at the top and a list of personal recommendations is presented
further down the page. When you type an author’s name, a title, or a keyword into
the search text box, a list of matching books appears. When you click a particular

book’s title, you are shown the book’s details along with comments and ratings from
other users. When you add the book to your shopping cart and check out, you are
prompted for a credit card number, which is then billed.
Web pages whose content is determined dynamically based on user input or other
information are called dynamic web pages. Any website’s search engine page is an
example of a dynamic web page because the content of the results page is based on
the search criteria the user entered and the searchable documents on the web server.
Another example is Amazon.com’s personal recommendations. The books and prod-
ucts that Amazon.com suggests when you visit the home page are different from the
books and products suggested for someone else. Specifically, the recommendations
are determined by the products you have previously viewed and purchased.
From the Library of Wow! eBook
www.it-ebooks.info
ptg
What Is ASP.NET?
9
By the
Way
The opposite of a dynamic web page is a static web page. Static web pages contain
content that does not change based on who visits the page or other external factors.
HTML pages, for example, are static web pages. Consider an HTML page on a web-
site with the following markup:
<html>
<body>
<b>Hello, World!</b>
</body>
</html>
Such a page is considered a static web page because regardless of who views the page
or what external factors might exist, the output will always be the same: the text
Hello, World! displayed in a bold font. The only time the content of a static web

page changes is when someone edits and saves the page, overwriting the old version.
Virtually all websites today contain a mix of static and dynamic web pages. Rarely
will you find a website that has just static web pages, because such pages are so
limited in their functionality.
It is important to understand the differences between how a website serves static web
pages versus dynamic web pages.
ASP.NET is only one of many technologies that can be employed to create
dynamic web pages. Other technologies include ASP—ASP.NET’s predecessor—
PHP, JSP, and ColdFusion. If you have experience developing web applications with
other web programming technologies, you may already be well versed in the mate-
rial presented in the next two sections. If this is the case, feel free to skip ahead
to the “Installing the .NET Framework, Visual Web Developer, and SQL Server
2008” section.
Did you
Know?
Serving Static Web Pages
If you’ve developed websites before, you likely know that a website requires a
web server.
A web server is a software application that continually waits for incoming web
requests, which are requests for a particular URL (see Figure 1.1). The web server
examines the requested URL, locates the appropriate file, and then sends this file
back to the client that made the request.
For example, when you visit Amazon.com, your browser makes a web request to
Amazon.com’s web server for a particular URL (say, /books/index.html).
From the Library of Wow! eBook
www.it-ebooks.info
ptg
10
HOUR 1: Getting Started with ASP.NET 4
Amazon.com’s web server determines what file corresponds to the requested URL and

returns the contents of this file to your browser.
This model is adequate for serving static pages, whose contents do not change. How-
ever, such a simple model is insufficient for serving dynamic pages because the web
server merely returns the contents of the requested URL to the browser that initiated
the request. The contents of the requested URL are not modified in any way by the
web server based on external inputs.
Serving Dynamic Web Pages
To accommodate dynamic content, dynamic web pages contain source code that is
executed when the page is requested (see Figure 1.2). The executing code produces
the HTML that is sent back to and displayed in the visitor’s browser.
Internet
The
appropriate
file is
requested
from the file
system
The file system returns
the contents of the file to
the Web server
The Web
server returns
the requested
file
Web server
receives Web
request
The Web browser
receives the requested
file (an HTML file) and

renders the HTML
markup graphically on
the computer screen.
Web browser
makes Web
request
Workstation Web
Server
File
System
FIGURE 1.1
The web server
handles incom-
ing web
requests.
FIGURE 1.2
The content of a dynamic web page is created by executing the dynamic web page’s source code.
The
appropriate
source code file
is requested
from the file
system
The file system returns
the contents of the source
code file to the Web
server. The Web server
then executes the source
code, which produces
HTML output.

The Web
server returns
the requesting
HTML output.
Web server
receives Web
request for a
dynamic Web
page
The Web browser
receives the requested
file (an HTML file) and
renders the HTML
markup graphically on
the computer screen.
Web browser
makes Web
request
Internet
Workstation
Web
Server
File
System
From the Library of Wow! eBook
www.it-ebooks.info

×