This page intentionally left blank
CORE INTERNET APPLICATION DEVELOPMENT WITH ASP.NET 2.0
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 email@example.com For sales outside the United States, please contact: International Sales firstname.lastname@example.org Visit us on the Web: www.prenhallprofessional.com
Library of Congress Cataloging-in-Publication Data Connolly, Randy, 1964Core Web application development with ASP .NET 2.0 / Randy Connolly. p. cm. Includes bibliographical references and index. ISBN 0-321-41950-2 (pbk. : alk. paper) 1. Active server pages. 2. Microsoft .NET. 3. Web servers. 4. Web site development. 5. Internet programming. I. Title. TK5105.8885.A26C67 2007 005.2'76—dc22
Copyright © 2007 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department One Lake Street Fax: (201) 236-3290 Upper Saddle River, NJ 07458 ISBN 0-321-41950-2 Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts. First printing, February 2007
To Diana, Alexander, Benjamin, and Norm. With much love.
This page intentionally left blank
Preface xxi Acknowledgments About the Author
CORE ASP.NET 1
INTRODUCING ASP.NET 2.0 3
Why ASP.NET? 3 Static Versus Dynamic Web Content 4 Competing Dynamic Server Technologies ASP.NET Advantages 8 .NET Framework 8 Components of .NET Framework 10 .NET Execution 14 ASP.NET Web Forms 15 C# Language 21 Web Application Structure 21
Visual Studio 2005 24 Visual Studio Web Projects 25 Web Server Options 26 Tutorial: Creating ASP.NET Web Forms 29 Creating a Web Site in Visual Studio 30 Adding a New Web Form 31 Adding HTML Content to a Web Form 33 Adding Programming Logic 39 Encountering Errors 43 Using the Visual Studio Debugger 46 Summary 50 Exercises 50 Key Concepts 50 References 51
HOW ASP.NET WORKS 53
ASP.NET Event Model 53 Postback 55 View State and Control State 57 Page Lifecycle 58 ASP.NET Code Compilation 72 Compilation Order 76 The Page Class 78 Request 79 Response 80 Server 80 ASP.NET Application Lifecycle 81 User Requests ASP.NET Resource from Server 82 ASP.NET Core Objects Are Created for the Request Assign HttpApplication Object to Request 89 Process Request Using HttpApplication Pipeline 92 Summary 94 Exercises 94 Key Concepts 94...