CYAN YELLOW MAGENTA BLACK PANTONE 123 CV BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN WEB DEVELOPMENT Companion eBook Available Pro Ajax and the .NET 2.0 Platform Pro Dear Reader, Thanks to the folks at Google, Ajax technology has become a force to be reckoned A with. It is a technology that is here and now, just waiting for developers to implement it. Google Maps, Google Suggest, and Flickr are just a few of the sites j out there that have moved Ajax into the mainstream. More will come as the a technology becomes easier to implement. This book will examine not only Ajax x technology, but also XmlHttpRequest processes, putting theory into code with Pro Ajax samples that duplicate many of the technologies utilized by the aforementioned cutting-edge websites. a and the Fortunately for C# developers, we have Ajax options right now in the form of n some newly released class libraries that open the Ajax door to the .NET d Framework. The majority of the code in this book centers on a third-party library called Anthem, written by Jason Diamond. One of the benefits of using t h this library is that you’ll also have backwards compatibility to Visual Studio .NET 2.0 e 2003, as a majority of the code in this book will work with .NET 1.1 or 2.0. Having that range of opportunity makes Ajax development accessible to all. Platform . You’ll also get an introductory look at Microsoft’s Atlas and how it holds up N against Ajax. You’ll have a chance to build an Atlas application as well and decide for yourself whether Atlas is the right fit for your development work. E I’m confident that this book will help you get a firm grasp on the dynamic tools that are available now. You’ll be ready for next-generation web develop- T ment in a surprisingly short amount of time. 2 Dan Woolston Join online discussions: . 0 forums.apress.com FOR PROFESSIONALS THE APRESS ROADMAP BY PROFESSIONALS™ P Foundations of Ajax l Companion eBook Ajax Patterns a and Best Practices t Pro Ajax and the f Illustrated C# .NET 2.0 Platform o Pro C# 2005 and the .NET r Foundations of Atlas: 2.0 Platform, Third Edition m See last page for details Rapid Ajax Development on $10 eBook version with ASP.NET 2.0 W Daniel Woolston ISBN 1-59059-670-6 SOURCECODEONLINE o 54999 o www.apress.com l s t o n US $49.99 Shelve in Web Development 6 89253 59670 8 9 781590 596708 User level: Intermediate–Advanced this print for content only—size & color not accurate spine = 0.924" 488 page count 6706fmfinal.qxd 6/20/06 3:40 PM Page i Pro Ajax and the .NET 2.0 Platform Daniel Woolston 6706fmfinal.qxd 6/20/06 3:40 PM Page ii Pro Ajax and the .NET 2.0 Platform Copyright © 2006 by Daniel Woolston All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-670-8 ISBN-10 (pbk): 1-59059-670-6 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Matthew Moodie Technical Reviewer: Nick McCollum Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Julie M. Smith Copy Edit Manager: Nicole LeClerc CopyEditor:Ami Knox Assistant Production Director: Kari Brooks-Copony Senior Production Editor: Laura Cheu Compositor: Linda Weidemann, Wolf Creek Press Proofreader: April Eddy Indexer: Broccoli Information Management Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], orvisit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected],or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.comin the Source Code section. 6706fmfinal.qxd 6/20/06 3:40 PM Page iii For Terry and Cathy Woolston. This book is a testament to the perseverance and faith that you have had throughout the years. Thank you. 6706fmfinal.qxd 6/20/06 3:40 PM Page iv Contents at a Glance About the Author .................................................................xv About the Technical Reviewer ......................................................xvi Acknowledgments ...............................................................xvii Introduction .....................................................................xix PART 1 n n n Ajax Concepts nCHAPTER 1 History and Revival of Ajax......................................3 nCHAPTER 2 Introducing JavaScript.........................................15 nCHAPTER 3 The XmlHttpRequest Object....................................41 nCHAPTER 4 N-Tier and Ajax................................................65 PART 2 n n n Ajax Components nCHAPTER 5 RichInternet Applications......................................91 nCHAPTER 6 CSS and the DOM.............................................101 nCHAPTER 7 Ajax Frameworks.............................................135 PART 3 n n n Concept to Code nCHAPTER 8 Understanding the Library ....................................149 nCHAPTER 9 Ajax and Web Services........................................181 nCHAPTER 10 Tagging with Ajax ............................................207 nCHAPTER 11 Cloning Google Suggest.......................................227 nCHAPTER 12 User Controls and Ajax.NET ...................................257 nCHAPTER 13 Ajax and Mapping ............................................271 nCHAPTER 14 Ajax and Web Parts...........................................299 iv 6706fmfinal.qxd 6/20/06 3:40 PM Page v PART 4 n n n Security and Performance nCHAPTER 15 Ajax and ASP.NET Security....................................329 nCHAPTER 16 Performance .................................................351 nCHAPTER 17 Debugging Your Application...................................373 nCHAPTER 18 Ajax and Site Testing .........................................391 nCHAPTER 19 Ajax Usability.................................................409 PART 5 n n n Moving Forward nCHAPTER 20 Atlas .........................................................425 nINDEX .......................................................................453 v 6706fmfinal.qxd 6/20/06 3:40 PM Page vi 6706fmfinal.qxd 6/20/06 3:40 PM Page vii Contents About the Author .................................................................xv About the Technical Reviewer ......................................................xvi Acknowledgments ...............................................................xvii Introduction .....................................................................xix PART 1 n n n Ajax Concepts nCHAPTER 1 History and Revival of Ajax..................................3 The Age of Discovery .............................................3 1970.......................................................3 1975.......................................................4 1979.......................................................4 1991.......................................................5 The Age of Implementation........................................5 1993.......................................................5 1994.......................................................5 The Age of War ..................................................5 1995.......................................................5 1996.......................................................6 1997.......................................................6 1998.......................................................7 1999.......................................................7 The Age of Transition.............................................8 2000.......................................................8 2001.......................................................8 The Age of Experimentation........................................9 2002–2004.................................................9 2005......................................................11 Summary ......................................................14 vii 6706fmfinal.qxd 6/20/06 3:40 PM Page viii viii nCONTENTS nCHAPTER 2 Introducing JavaScript .....................................15 HTML Presence.................................................15 Scripting Load Cycle.............................................19 During Document Load......................................19 After Document Load .......................................20 When Called by Other JavaScript Statements ..................21 Variables.......................................................22 Concatenating and Adding...................................23 Variable Scope.............................................23 Control Structures..........................................23 Looping and Iteration ............................................24 while Loops................................................25 do/while Loops.............................................25 for Loops..................................................26 Switch Statements ..............................................27 Functions ......................................................29 Returning Values ...........................................30 Arrays .........................................................30 Creating an Array...........................................30 Objects ........................................................32 Declaring Properties ........................................33 Declaring Functions.........................................34 Error Handling ..................................................37 Summary.......................................................39 nCHAPTER 3 The XmlHttpRequest Object................................41 Initialization ....................................................42 LOADVIEWSTATE................................................42 LOADPOSTBACKDATA............................................42 LOAD..........................................................42 RAISEPOSTBACKEVENT ..........................................43 SAVEVIEWSTATE ................................................43 Render.........................................................43 Asynchronous Resource Retrieval .................................45 Header Requests................................................50 Retrieving XML Data.............................................52 Introducing JSON................................................57 Summary ......................................................64 6706fmfinal.qxd 6/20/06 3:40 PM Page ix nCONTENTS ix nCHAPTER 4 N-Tier and Ajax .............................................65 What Is N-Tier? .................................................65 Application Layer...........................................68 Business Layer.............................................69 Data Layer.................................................70 Data Store.................................................72 The Place for Ajax...............................................72 Sample N-Tier Application........................................73 Presentation Layer..........................................74 Business Layer.............................................82 Data Layer.................................................86 Data Store.................................................88 Summary.......................................................88 PART 2 n n n Ajax Components nCHAPTER 5 Rich Internet Applications..................................91 What It Is Not...................................................91 What It Could Be ................................................91 Cross-browser Support......................................92 Client-side Logic Handling...................................92 Application Installation ......................................92 Browser Transition Logic....................................94 RIA Recommendations...........................................94 Focused Interaction.........................................94 Page Disruptions ...........................................95 Compelling Navigation ......................................97 URL Linking ....................................................98 Summary .....................................................100
Description: