Designing_Microsoft_ASP.NET_Applications (VBL).pdf

(3329 KB) Pobierz
Designing Microsoft ASP.NET Applications
Douglas J. Reilly
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright © 2002 by Douglas J. Reilly
All rights reserved. No part of the contents of this book may be reproduced or transmitted in
any form
or by any means without the written permission of the publisher.
Library of Congress Cataloging-in-Publication Data
Reilly, Douglas J.
Designing Microsoft ASP.NET Applications / Douglas J. Reilly.
p. cm.
Includes index.
ISBN 0-7356-1348-6
1. Internet programming. 2. Active server pages. 3. Web servers. I. Title.
QA76.625 .R45 2001
005.2'76-dc21 2001051310
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 QWE 6 5 4 3 2 1
Distributed in Canada by Penguin Books Canada Limited.
A CIP catalogue record for this book is available from the British Library.
Microsoft Press books are available through booksellers and distributors worldwide. For
further information about international editions, contact your local Microsoft Corporation
office or contact Microsoft Press International directly at fax (425) 706-7329. Visit our Web
site at www.microsoft.com/mspress. Send comments to mspinput@microsoft.com .
ActiveX, JScript, Microsoft, Microsoft Press, MS-DOS, Visual Basic, Visual C++, Visual
Studio, Windows, and Windows NT are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Other product and
company names mentioned herein may be the trademarks of their respective owners.
The example companies, organizations, products, domain names, e-mail addresses, logos,
people, places, and events depicted herein are fictitious. No association with any real
company, organization, product, domain name, e-mail address, logo, person, place, or event is
intended or should be inferred.
Acquisitions Editor
David Clark
Project Editor
Sally Stickney
Manuscript Editor
Jennifer Harris
Body Part No. X08-06257
For Jean, Tim, and Erin-
I owe my life to the people I love.
The manuscript for this book was prepared and galleyed using Microsoft Word 2002. Pages
were composed by Microsoft Press using Adobe PageMaker 6.52 for Windows, with text in
Garamond and display type in Helvetica Condensed. Composed pages were delivered to the
printer as electronic prepress files.
Cover Designer
Methodologie, Inc.
Interior Graphic Designer
James D. Kramer
Principal Compositor
Carl Diltz
Interior Artist
Joel Panchot
Principal Copy Editor
Cheryl Penner
Indexer
Shane-Armstrong Information Systems
About the Author
Ever since he convinced his wife to spend what seemed like far too much money on an Atari
800, Douglas J. Reilly has loved to play with computers. For many years before that, he made
a living repairing photocopiers and early personal computers. But after a while, the software
seemed to be more fun than the hardware.
Doug is the owner of Access Microsystems Inc., a small consulting firm that develops
software using Microsoft Visual C++, Borland Delphi, Microsoft Access, and the Microsoft
.NET Framework. He has created applications to electronically test job applicants, track
retailer's inventory, and repair damaged databases. Currently he is working on a variety of
healthcare applications for the St. Barnabas Health Care System as well as applications for the
golf and leisure industry for Golf Society of the U.S., both in New Jersey. In addition to
developing software, Doug has published articles in Dr. Dobb's Journal and Software
Development , and he wrote a column in the Pervasive Software Developer's Journal . He has
also published another book with Microsoft Press, Inside Server-Based Applications (2000).
Doug lives with his wife, Jean, and their two children, Tim and Erin. When not programming,
he enjoys music, reading, and bicycle riding, although book writing and other concerns have
conspired against serious riding this year. Maybe next year.
Doug can be reached by e-mail at doug@ProgrammingASP.NET .
Acknowledgments
I'm one of a relatively small group of people: long-term survivors of liver cancer. As I was
writing my last book, I was diagnosed with and treated for liver cancer. That I am here to
write about it almost four years later is a testament to good fortune, good technology, and
good people. First among the good people who got me this far is Dr. Hans Gerdes at
Memorial Sloan Kettering Cancer Center, who, along with his office assistant, Joanne Booth-
Pezantez, didn't take 'We don't know what that spot on Doug's liver is' for an answer. Dr.
Gerdes is more than a doctor; he has become someone I trust for advice and support for all the
chaos caused by Familial Adenomatous Polyposis, the disease at the root of my family's
health problems. For more information on this and other hereditary colon cancers, see
http://www.hereditarycc.org .
I must mention the 'Freds' (Fred Stodolak and Fred Paliani), Jim Hoffman, Rich Iavarone,
Tara O'Neill, and Jason Nadal at Golf Society of the U.S. The Freds provided a work
environment that allowed me to use neat technology while not requiring me to dress up. They
also kindly allowed me to use a couple of the articles from the Golf Society of the U.S. Web
site ( http://www.golfsociety.com ) for an example in Chapter 10. Jim was the best boss a guy
could have, especially a guy like me who likes to hole up in the basement and play with
computers. Jim has looked at some of the chapters, and his honest assessment of what makes
sense and what doesn't has helped me a great deal. Rich and Jason have given me a hand on
occasion with JavaScript questions. Tara worked some magic on my picture for use in the
author bio page. Trust me, she didn't have much to work with! Thanks, all.
In my spare time, I do a great deal of work for the St. Barnabas Healthcare System (SBHCS).
Kathy Collins and Rich Wheatley have allowed me to continue working on cool projects in
the four years or so since I left full-time employment there. SBHCS has provided a wonderful
environment for creating cool systems that work on one of the largest intranets in the state. In
addition to Rich and Kathy, I also work closely with Darcy Kindred (an interface goddess),
Ryan Grim, and Joanne Gibson, among others. Thanks for your patience while I was writing
this book. A special thanks to the folks in the SBHCS Behavioral Health Call Center, who
have put up with delays in making changes to their system due to my too busy schedule
during the writing of this book.
Susan Warren at Microsoft was an amazing help, answering more than one frazzled e-mail
when I was late delivering a chapter and the examples just wouldn't work. Her patience in
pointing out my mistakes and her willingness to dig in to get to the bottom of things when
there was a real problem helped immensely. Susan, along with Scott Guthrie and Rob
Howard, also provided great support for me and all the ASP.NET authors, starting what seems
like a lifetime ago, back at the first ASP.NET author's summit.
At that first ASP.NET author's summit, I happened to get teamed up with G. Andrew Duthie
of Graymad Enterprises for a hands-on exercise. Since then, we have corresponded and
commiserated through e-mail and in person at various conferences. Andrew's book on
ASP.NET should be finished 'real soon now,' and I encourage you to take a look at it when it
hits the shelves. Andrew is perhaps the most outspoken proponent of Microsoft technology
that I know, and he uses that technology to do some neat things. Others who I trust for
technical feedback and just plain advice include Ed Colosi, Tom Dignan, Michael Zaccardi,
and Sue Shaw. Claudette Moore, my agent, worked harder on this book than she might on
some others. Thank you for getting in there and helping me organize my thoughts.
Writing a book for Microsoft Press is different than most other book-writing experiences. But
writing this book was different than even the normal Microsoft Press experience. This is not
exactly the book I had initially planned, due in part to the huge success of ASP.NET, even in
beta. Because of this unexpected success, it was important to get the book out there, even if
that meant some last-minute changes. My editor, Sally Stickney; Jennifer Harris, the
manuscript editor; David Clark, the acquisitions editor; and Robert Lyon, the technical editor,
have all been amazing even in the face of seemingly unreasonable deadlines, the normal beta
software weirdness, and my constantly remembering one more great thing I needed to add.
Robert especially has saved me from myself on more than one occasion. Thanks!
Of course, living with an author while he or she is writing a book can be quite an experience
as well. Erin, my daughter, has ensured that I continue to be involved in some of the finer
things in life, such as Ani DiFranco's music. I can't wait for that concert coming up! My son,
Tim, reminded me all summer how important exercise is, and I really did listen. Thanks for
the walks and the bike rides!
Jean, my wife of 23 years, has long been the rock that grounds our family. While I may drift
off on this or that tangent, Jean is the one who makes sure everything that needs to be done
gets done. In the case of our family, that includes almost daily dealings with one health
insurance company or another. For that alone, she has earned a seat in heaven. Of course,
there's much more than that. You know that whole, 'In sickness and in health, for better or
worse' agreement? Jean really meant it! There has been more health than sickness , and more
better than worse , but you really know someone will be there for you when they are there for
you at the worst time of your life and show no signs of giving up on you. Jean, may we spend
forever together, with 100-year extensions!
Introduction
When I look down, I miss all the good stuff.
And when I look up, I just trip over things.
-Ani DiFranco
When I first heard about ASP.NET at a Microsoft author's conference over a year ago, I
thought it might just be too good to be true. I can now create Web pages that are based on
compiled code, in one of many very cool, object-oriented languages? I can use real variables
with types and all? I can create server-side components using the .NET languages that will
allow me to encapsulate all kinds of functionality that my applications need, and I don't have
to worry about deploying COM components? I can use special validator components to
magically test values entered on the client and the server? As I said, it sounded too good to be
true.
In fact, ASP.NET lets you do all that and more. ASP.NET has quite simply changed the way I
build Web applications. While doing some heavy-duty Active Server Pages (ASP)
programming, I always tried to move any functionality I could into the database because the
deployment issues in the database were much easier to deal with than the deployment issues
with ASP files spread over a cluster of machines. I no longer have to do that, and neither will
you!
Of course, with the new abilities comes some additional complexity. The only thing harder
than working with all this new Microsoft .NET Framework complexity is trying to describe it.
While working on many of the chapters in this book, I felt like the writer quoted above.
Dealing with all the nitty-gritty details might hide the total coolness of what I was doing, yet
just looking at the cool results without seeing the details can trip you up.
I've tried to give you the details you need to know to get the job done, but the entire .NET
Framework is huge . There are literally thousands of classes. In many places, I've referred you
to the MSDN documentation included with the .NET Framework, and I encourage you to use
it. If you need to do something with strings, look up the System.String class on MSDN. If file
access is important, look at the System.IO namespace. I've tried to refrain from reproducing
the same information that the MSDN documentation offers, except in areas in which
exhaustive reference source, and this book is more of a tutorial that, after some basics are
covered, will take you through real-world problems and solutions. Both types of information
sources have their place.
Who Should Read This Book
ASP.NET provides an opportunity for developers currently working with ASP to create more
powerful and scalable Web applications. At the same time, ASP.NET provides developers
who haven't previously been involved with Web development with a new opportunity to
begin developing Web applications. Because of the two likely audiences for this book, I don't
assume that all readers will have tremendous experience with Web development. That said, if
you don't understand HTML at all, you need to make sure you know at least what's covered in
Appendix B.
Because you can use both Microsoft Visual Basic .NET and C# with ASP.NET, I don't focus
on one language to the exclusion of the other. A Visual Basic programmer or a C++
programmer new to ASP.NET should be able to follow the samples. The samples alternate
between Visual Basic .NET and C#. In the few cases in which the programming language
matters, I've shown the samples in both languages or, more frequently, pointed out the
differences between the languages. Learning the .NET Framework is the better part of the
work required to learn to use ASP.NET.
Overview of the Book
Zgłoś jeśli naruszono regulamin