Here I am, seven years after the inception of ASP, still using a technology
that I initially only glanced over as I searched for a server-side alternative
It was 1997, a big year for me. I graduated college, landed a job as
a creative director, and decided it was time to build on my experience with
true passions lay in design—but within months of starting my new job,
I was developing the firm’s Website, Intranet, and company portal. The
dynamic portions of these projects were developed using CGI written in Perl.
As you might expect, I was lost! After looking around, I decided ColdFusion
was my best bet—the language seemed to parallel closely the constructs
of HTML, and I found it easy to pick up. However, I soon discovered that ColdFusion’s
limitations in terms of accessing a server’s file system, and error
handling, posed problems.
ASP and VBScript seemed like the best alternative. I’d taken basic
programming classes in college, and I guess they helped, because these two
technologies came easily to me. Shortly thereafter, I went back to school
and got into Visual Basic, COM, DCOM, and more. A whole new world was opening
up to me through simplicity offered by ASP.
Seven years, and countless Windows, Web, and wireless applications later,
I still swear by the next generation of a technology that I’ve always
considered superior to the major alternatives. ASP.NET represents a new and
efficient way of creating Web applications using the programming language
with which you feel most comfortable. Though it can take some time to learn,
ASP.NET is simple to use. Whether you want to create Web Forms complete with
Web and validation controls, or you aim to build a feature-rich shopping cart
using DataTables, all the tools you’ll need to
get up and running are immediately available, easy to install, and require
very little initial configuration.
My guess is that if you’re reading this book, you’re in
the same boat I was: a longtime designer dabbling with HTML. Or maybe you’re
you’re a seasoned PHP, JSP, or ColdFusion veteran who wants to know
what all the fuss is about. Whatever the case, I’m sure you’ll
find this book helpful in showing you how simple and feature-rich ASP.NET
Who Should Read This Book?
This book is aimed at beginner, intermediate, and advanced Web designers
looking to make the leap into server-side programming with ASP.NET. You’ll
be expected to feel comfortable with HTML, as very little explanation is provided
By the end of this book, you should have a firm grasp on what it takes
to download and install ASP.NET and the .NET Framework, configure and start
your Web server, create and work with basic ASP.NET pages, install and run
either Access or MSDE, create database tables, work with advanced, dynamic
ASP.NET pages that query, insert, update, and delete information within a
All examples provided in the book are written in both Visual Basic .NET
and C#, the two most popular languages for writing ASP.NET Websites. They
start at beginners’ level and work up. As such, no prior knowledge of
the two languages is required in order to read, learn from, and apply the
knowledge provided in this book. Experience with other programming or scripting
and will enable you to grasp the fundamental programming concepts more quickly.
What’s Covered In This Book?
This book is comprised of the following seventeen chapters. Read them
from beginning to end to gain a complete understanding of the subject, or
skip around if you feel you need a refresher on a particular topic.
Before you can start building your database-driven Web presence, you
must ensure you have the right tools for the job. In this first chapter, I’ll
tell you how to find, download, and configure the .NET Framework. I’ll
explain where the Web server is located and how to install and configure it.
Next, we’ll walk through the installation of two Microsoft database
solutions: Access and MSDE. Finally, we’ll create a simple ASP.NET page
to make sure that everything’s running and properly configured.
In this chapter, you’ll create your first useful ASP.NET page.
We’ll cover all of the parts that make up a typical ASP.NET page, including
directives, controls, and code. We’ll then walk through the process
of deployment, focusing specifically on allowing the user to view the processing
of a simple ASP.NET page through the Web browser.
In this chapter, we’ll look at two of the programming languages
used to create ASP.NET pages: VB.NET and C#. You’ll learn about the
syntax of the two languages as we explore the concepts of variables, data
types, conditionals, loops, arrays, functions, and more. Finally, we’ll
see how the two languages accommodate Object Oriented Programming principles
by allowing you to work with classes, methods, properties, inheritance, and
ASP.NET is bundled with hundreds of controls that you can use within
your applications, including HTML controls, Web controls, and more. This chapter
will introduce you to the wonderful world of Web controls and how Microsoft
basically reinvented HTML forms.
Undoubtedly one of the most important chapters in the book, Chapter 6, Database Design and Development will
help you prepare to work with databases in ASP.NET. We’ll cover the
essentials you’ll need in order to create a database using either Access
or MSDE. In this chapter, we’ll begin to build the database for our
This chapter introduces the language we’ll use to facilitate communications
between the database and the Web application: Structured Query Language, or
SQL. After a gentle introduction to the basic concepts of SQL, we’ll
move on to more advanced topics such as expressions, conditions, and joins.
The next logical step in database driven Web applications involves ADO.NET.
This chapter explores the essentials of the technology, and will have you
reading data in a database directly from your Web applications in just a few
short steps. We’ll then help you begin the transition from working with
static applications to database-driven ones.
Taking ADO.NET further, this chapter shows you how to utilize the DataGrid and DataList controls
provided within the .NET Framework. DataGrid and DataList play
a crucial role in the simplicity of presenting information with ASP.NET. In
learning how to present database data within your applications in a cleaner
and more legible format, you’ll gain an understanding of the concept
of data binding at a much higher level.
One of the most challenging concepts to grasp when transitioning from
ASP to ASP.NET is that of disconnected data. In this chapter, you’ll
learn how to use DataSets to create virtual database
tables within your Web applications. You’ll also learn how to work with DataTables,
and how to filter and sort information within DataSets
and DataTables using DataViews.
Chapter 11, Web Applications explores the features of a Web application.
We’ll discuss the many parts of the Web.config file
in depth, and understand how to work with the Global.asax file,
application state, and session state. Finally, we’ll look at the ways
in which caching can improve the performance of your Web applications.
In this chapter, we’ll create an ASP.NET shopping cart. Using
the topics we’ve explored in previous chapters, including DataTables
and session state, we’ll walk through the process of building a purely
memory-resident shopping cart for our project.
Learning to handle gracefully unforeseen errors within your Web applications
is the topic of this chapter. Initially, we’ll discuss basic page and
code techniques you can use to handle errors. We’ll then talk about
the debugger that’s included with the .NET Framework SDK and understand
how to leverage it by setting breakpoints, reading the autos and locals window,
and setting watches. Finally, we’ll discuss how you can take advantage
of the Event Viewer to write errors as they occur within your applications.
This chapter will introduce you to securing your Web applications with
ASP.NET. Here, we’ll discuss the various security models available,
including IIS, Forms, Windows, and Passport, and discusses the roles the Web.config and
XML files can play.
In this chapter, we’ll look at accessing your server’s file
system, including drives, files, and the network. The chapter will then show
you how to work with file streams to create text files, write to text files,
and read from text files on your Web server. Finally, you’ll learn how
to send emails using ASP.NET.
Chapter 16, Rich Controls and User Controls explores ASP.NET’s rich controls.
You’ll learn how to create an interactive meeting scheduler using the Calendar control,
sessions, and serialization. You’ll also learn how to format XML with
XSLT utilizing the Xml control. Lastly, we’ll
look at randomizing banner advertisements on your site using the AdRotator control.
The newest buzzword in the development community is “Web Services,”
and this chapter hopes to shed some light on the topic. We first define Web
Services before moving on to explain how they’re used, where they can
be found, and what WSDL and UDDI are. In this chapter, you’ll create
a couple of different Web Services from scratch, including one that queries
your database to present information within a Web application. You’ll
also learn how to build a search application using the Google Search Web Service.
As you progress through this book, you’ll note a number of references
to the code archive. This is a downloadable ZIP archive that contains complete
code for all the examples presented in the book.
The archive contains one folder for each chapter of the book. Each of
these folders in turn contains CS and VB subfolders,
which contain the C# and VB.NET versions of all the examples for that chapter,
respectively. In later chapters, these files are further divided into two
more subfolders: Lessons for standalone examples presented
for a single chapter, and Project for files associated
with the Dorknozzle Intranet Application, a larger-scale project that we’ll
work on throughout the book, which I’ll introduce in Chapter 4, Web Forms and Web Controls.
Updates and Errata
No book is perfect, and we expect that watchful readers will be able
to spot at least one or two mistakes before the end of this one. The Errata
page on the book’s Website will always have the latest information about
known typographical and code errors, and necessary updates for new releases
of ASP.NET and the various Web standards that apply.
The SitePoint Forums
If you’d like to communicate with me or anyone else on the SitePoint
publishing team about this book, you should join SitePoint’s
online community. The
.NET forum in particular can offer an abundance of information above
and beyond the solutions in this book.
In fact, you should join that community even if you don’t want
to talk to us, because there are a lot of fun and experienced Web designers
and developers hanging out there. It’s a good way to learn new stuff,
get questions answered in a hurry, and just have fun.
The SitePoint Newsletters
In addition to books like this one, SitePoint publishes free email newsletters
including The SitePoint Tribune and The
SitePoint Tech Times. In them, you’ll read about the latest
news, product releases, trends, tips, and techniques for all aspects of Web
development. If nothing else, you’ll get useful ASP.NET articles and
tips, but if you’re interested in learning other technologies, you’ll
find them especially valuable. Sign up to one or more SitePoint newsletters
If you can’t find your answer through the forums, or if you wish
to contact us for any other reason, the best place to write is <email@example.com>.
We have a well-manned email support system set up to track your inquiries,
and if our support staff members are unable to answer your question, they
will send it straight to me. Suggestions for improvements as well as notices
of any mistakes you may find are especially welcome.
First and foremost, I’d like to thank the SitePoint team for doing
such a great job in making this book possible, for being understanding as
deadlines inevitably slipped past, and for the team’s personal touch,
which made it a pleasure to work on this project.
Particular thanks go to Simon Mackie, whose valuable insight and close
cooperation throughout the process has tied up many loose ends and helped
make this book both readable and accessible. Thanks again Simon for allowing
me to write this book—I appreciate the patience and dedication that
Finally, returning home, I’d like to thank my wife Jessica, whose
patience, love and understanding throughout continue to amaze me.