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

pro ajax and the .net 2.0 platform (2006)

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.27 MB, 486 trang )

this print for content only—size & color not accurate spine = 0.924" 488 page count
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Pro Ajax and the .NET 2.0 Platform
Dear Reader,
Thanks to the folks at Google, Ajax technology has become a force to be reckoned
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
out there that have moved Ajax into the mainstream. More will come as the
technology becomes easier to implement. This book will examine not only Ajax
technology, but also XmlHttpRequest processes, putting theory into code with
samples that duplicate many of the technologies utilized by the aforementioned
cutting-edge websites.
Fortunately for C# developers, we have Ajax options right now in the form of
some newly released class libraries that open the Ajax door to the .NET
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
this library is that you’ll also have backwards compatibility to Visual Studio
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.
You’ll also get an introductory look at Microsoft’s Atlas and how it holds up
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.
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-
ment in a surprisingly short amount of time.
Dan Woolston
US $49.99
Shelve in
Web Development
User level:


Intermediate–Advanced
Ajax and the .NET 2.0 Platform
Woolston
THE EXPERT’S VOICE
®
IN WEB DEVELOPMENT
Daniel Woolston
Pro Ajax and the
.NET 2.0 Platform
CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 CV
ISBN 1-59059-670-6
9 781590 596708
54999
6 89253 59670 8
Companion
eBook Available
www.apress.com
SOURCE CODE ONLINE
Companion eBook
See last page for details
on $10 eBook version
forums.apress.com
FOR PROFESSIONALS
BY PROFESSIONALS

Join online discussions:

THE APRESS ROADMAP
Pro Ajax and the
.NET 2.0 Platform
Illustrated C#
Foundations of Atlas:
Rapid Ajax Development
with ASP.NET 2.0
Foundations of Ajax
Pro C# 2005 and the .NET
2.0 Platform, Third Edition
Ajax Patterns
and Best Practices
Pro
Daniel Woolston
Pro Ajax and the
.NET 2.0 Platform
6706fmfinal.qxd 6/20/06 3:40 PM Page i
P
ro 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
Copy Editor: 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
,
or visit .
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 , or visit .
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
in the Source Code section.
6706fmfinal.qxd 6/20/06 3:40 PM Page ii
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 iii
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
PART 1
■ ■ ■
Ajax Concepts
■CHAPTER 1 History and Revival of Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
■CHAPTER 2 Introducing JavaScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
■CHAPTER 3 The XmlHttpRequest Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
■CHAPTER 4 N-Tier and Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
PART 2
■ ■ ■
Ajax Components
■CHAPTER 5 Rich Inter
net Applications
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
■CHAPTER 6 CSS and the DOM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
■CHAPTER 7 Ajax Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
PART 3
■ ■ ■
Concept to Code
■CHAPTER 8 Understanding the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
■CHAPTER 9 Ajax and Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
■CHAPTER 10 Tagging with Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
■CHAPTER 11 Cloning Google Suggest. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

227
■CHAPTER 12 User Controls and Ajax.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
■CHAPTER 13 Ajax and Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
■CHAPTER 14 Ajax and Web Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
iv
6706fmfinal.qxd 6/20/06 3:40 PM Page iv
PART 4
■ ■ ■
Security and Performance
■CHAPTER 15 Ajax and ASP.NET Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
■CHAPTER 16 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
■CHAPTER 17 Debugging Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
■CHAPTER 18 Ajax and Site Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
■CHAPTER 19 Ajax Usability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
PART 5
■ ■ ■
Moving Forward
■CHAPTER 20 Atlas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
v
6706fmfinal.qxd 6/20/06 3:40 PM Page v
6706fmfinal.qxd 6/20/06 3:40 PM Page vi
Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
PART 1
■ ■ ■
Ajax Concepts

■CHAPTER 1 History and Revival of Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Age of Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1970. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1975. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1979. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1991. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The
Age of Implementa
tion
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
vii

6706fmfinal.qxd 6/20/06 3:40 PM Page vii
■CHAPTER 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
Dec
laring Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
■CHAPTER 3 The XmlHttpRequest Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
LOADVIEWSTATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

LOADPOSTBACKDA
T
A
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
LOAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
RAISEPOSTBACKEVENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
SA
VEVIEWST
ATE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
Render. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Asynchronous Resource Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Header Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Retrieving XML Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Introducing JSON. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
64
■CONTENTSviii
6706fmfinal.qxd 6/20/06 3:40 PM Page viii
■CHAPTER 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
■ ■ ■
Ajax Components
■CHAPTER 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
■CONTENTS
ix
6706fmfinal.qxd 6/20/06 3:40 PM Page ix
■CHAPTER 6 CSS and the DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Style Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Inline Style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Script Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
CSS Selectors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
CSS Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
CSS Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Site-wide Style Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
CSS Element Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Positioning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Element Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Document Object Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
How the DOM Came to Be . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Definition of the DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Working with the DOM Node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Modifying Style Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Debugging DOM issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Using the Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Default.aspx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
dataFetch.aspx.cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
■CHAPTER 7 Ajax Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Non NET and Cross-Platform. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Ruby on Rails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Dojo Toolkit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
SAJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
xajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
139

DWR: Direct Web Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
W
ebORB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
139
.NET F
rameworks and Libraries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
140
Michael Schwarz’s Ajax.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Jason Diamond’s Anthem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
ComfortASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
MagicAjax.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Microsoft’s Atlas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
146
■CONTENTSx
6706fmfinal.qxd 6/20/06 3:40 PM Page x
PART 3
■ ■ ■
Concept to Code
■CHAPTER 8 Understanding the Library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
The Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Installing the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
The Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Examining the Anthem Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Anthem.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

■CHAPTER 9 Ajax and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
So What Is a Web Service? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
SOAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Affecting Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Creating the Web Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Building the Ajax Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Accessing with XmlHttpRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
■CHAPTER 10 Tagging with Ajax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Creating the Da
tabase
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
The Tagging Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
HTML Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
C# Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
■CHAPTER 11 Cloning Google Suggest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Introducing Google Suggest. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
227
Implementing Google Suggest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
SearchP
a
ge.aspx
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
228
SearchP
a
ge.aspx.cs
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
231

SearchPage_DataSets.aspx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
SearchPage_DataSets.aspx.cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
SearchPage_Objects.aspx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
SearchPage_Objects.aspx.cs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Using a DataTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Using a Da
taSet
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
245
Using a Custom Data Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
■CONTENTS
xi
6706fmfinal.qxd 6/20/06 3:40 PM Page xi
Expanding the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Possible Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
■CHAPTER 12 User Controls and Ajax.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Setting Up Our Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Building the User Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
ClientID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Google Suggest Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
■CHAPTER 13 Ajax and Mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Ajax Traffic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Default.aspx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Default.aspx.cs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Microsoft’s Virtual Earth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Map Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Pushpins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Yahoo Traffic Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Yahoo Response Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Image Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Item Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Using the Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
■CHAPTER 14 Ajax and Web Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Web Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Ajax and Web Parts Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
ucCustomerLocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Tracking ZIP Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Y
ahoo! Sta
tic Ma
ps
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
322
Building the Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
326
■CONTENTSxii
6706fmfinal.qxd 6/20/06 3:40 PM Page xii
PART 4
■ ■ ■
Security and Performance
■CHAPTER 15 Ajax and ASP.NET Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Ajax As a Secure Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329

ASP.NET 2.0 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Setting Up a Site for Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Login Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
CreateUserWizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Login Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Testing the Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Ajax on Protected Login P
ages
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Forms Authentication and SQL Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Using ASP.NET 2.0 Membership with a SQL Server Database
of Your Choice
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
■CHAPTER 16 Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Monitoring Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Server Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Ajax P
erformance vs. Postback Performance
. . . . . . . . . . . . . . . . . . . . . . . 356
Comparing the Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Comparing JSON and XML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Our Findings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
■CHAPTER 17 Debugging Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373

Edit and Continue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
374
Using
Visualizers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
375
Enhanced DataTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Just My Code Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Third-party Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Fiddler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Microsoft’s Developer Toolbar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
389
■CONTENTS
xiii
6706fmfinal.qxd 6/20/06 3:40 PM Page xiii
■CHAPTER 18 Ajax and Site Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Stress Test Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Creating the Application to Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Using the Test Suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Testing the Postback Page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Testing the Ajax Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
■CHAPTER 19 Ajax Usability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
The Back Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Ajax Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Ajax Type-Aheads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Bookmarking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414

Connected Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Disabled JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Page Shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Dynamic Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Visible Source. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Page Paradigms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Universal Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Session Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Summar
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
PART 5
■ ■ ■
Moving Forward
■CHAPTER 20 Atlas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
What Atlas Is. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Do
wnloading
Atlas
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
427
Examining the Atlas Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Using
Atlas for the F
irst
Time
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
429
The Non-Atlas
A

pplication
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
429
The Atlas Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
AutoCompleteBehavior Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
453
■CONTENTSxiv
6706fmfinal.qxd 6/20/06 3:40 PM Page xiv
fa938d55a4ad028892b226aef3fbf3dd
About the Author
■DANIEL WOOLSTON is a software engineer from the Grand Rapids, Michigan
area. Daniel’s software journey began in the late 1980s with the infamous
Sinclair ZX80. His current ambitions involve developing next-generation
.NET web applications utilizing the latest technologies and beyond. His
work efforts have branched from Fortune 500 enterprise application devel-
opment to pattern-driven project implementations on various corporate
levels. He has years of experience in designing and distributing JavaScript/
.NET components as well as numerous VB/VB .NET/C# development projects. When he’s not
cutting through code, he can usually be found in his makeshift mad-scientist basement lab
building robots, one of which was recently featured in a national robotics magazine.
xv
6706fmfinal.qxd 6/20/06 3:40 PM Page xv
About the Technical Reviewer
■NICK MCCOLLUM has over 18 years of experience designing and developing
enterprise applications on a variety of platforms. He is a principal consult-
ant for NuSoft Solutions, Inc., and for the past year has been the architect
and lead developer for Spout (www.spout.com). In addition to this publica-
tion, Nick has acted as a technical reviewer for

C# COM+ Programming by
Derek Beyer (Hungry Minds, 2001). He is a Microsoft Certified Solution
Developer and was recently named one of the first Community Server MVPs
by Telligent Software. In his free time, Nick coaches youth basketball and soccer and is a fre-
quent presenter at Microsoft events and .NET user group meetings in the West Michigan area.
xvi
6706fmfinal.qxd 6/20/06 3:40 PM Page xvi
Acknowledgments
This book is barely the work of one man. So many people have shaped and contributed to
the work as a whole that I will find it difficult to name them all. But if I miss anyone, it is an
oversight and not a lack of gratitude.
First and foremost, I must thank Gary Cornell and Ewan Buckingham for making the
book a reality. I can’t imagine writing for anyone else. Thank you for your spontaneous words
of encouragement and leadership on this project.
I also must give a special thanks to Nick McCollum for his enduring patience during the
technical editing phase of the project. Without Nick’s encouragement and mentoring, this
would have been a hard book to write.
Thank you to the Apress team for your continuous and positive efforts: Laura Cheu,
Matthew Moodie, Ami Knox, and Tina Nielsen. A special thanks to Julie Smith, who always
seemed to know when I was in need of encouragement and was ready to help at a moment’s
notice.
I’d also like to express my undying gratitude to the NuSoft Solutions team. Your desire to be
the best in the industry has certainly brought out the best in me. Thanks to all: Brian Anderson,
Jim Becher, Aaron Kamphuis, Kevin Schultz, Rick Krause, Ted Walker, Mike Perry, CS Tang,
Bruce Abernethy, Jack Leung, Bruce Benson, Keith Brophy, Dale Mansour, and Bob Kreha.
Thanks also to Adrian Pavelescu, Ryan Smallegan, and Stacy Rood for their words of
encouragement and for helping me keep things in perspective.
I also need to say a special thanks to the founding members of Spout: Rick DeVos, Daryn
Kuipers, Dave DeBoer, Paul Moore, and Bill Holsinger-Robinson. Without your vision and faith
in cutting-edge web technology, this book would not have been possible.

Lastly, I must offer up an endless supply of appreciation and respect to Michelle, Aymee,
and Michael Woolston. You have graciously given up a daddy and a husband for most of the
year so that I could accomplish a long-standing goal. And now that I’ve finished the book,
I
find that the greatest achievement was not the book itself, but the encouragement and
patience that you’ve given me for the last few months. Thank you so much!
xvii
6706fmfinal.qxd 6/20/06 3:40 PM Page xvii
6706fmfinal.qxd 6/20/06 3:40 PM Page xviii
Introduction
It’s been well over a year since I first began working with the team over at Spout (www.spout.
com
). In the course of that year, I’ve been professionally challenged by the sheer amount of
cutting-edge work that I have been asked to develop. I can still remember Brian Anderson
(NuSoft Solutions) coming to Nick McCollum and me with a few sheets of paper detailing a
new third-party web tool that we should take a look at. The design documents were a brief
listing of the sample code for Ajax.NET by Michael Schwarz. Not only had Michael built an
awesome library, but he had done so for free. Nick and I embraced the library without hesi-
tation. Admittedly, we overused the library at first. We Ajax’d the site to its fullest extent. Need
a user control built? Use Ajax! At least that is how it felt at first. We were truly excited (and remain
so today) about the possibilities of Ajax and where it would lead our project. I want to share
this excitement with you.
An Overview of This Book
I want to deal with the world of Ajax to its finest detail. In order to do that, we’ll need to discuss
where Ajax came from, what it comprises, and how we can implement modern third-party Ajax
libraries. The technology is ever changing, and I encourage you to visit the various author sites
found throughout the book so that you may stay up to date. Many of the chapters have real-
world application, and you may find yourself coming back to the book as a reference for future
projects. I would also encourage you to blog about your work and the obstacles you overcome.
Had Peter Bromberg (

) not taken the time to blog about
his Ajax application, this book may have taken an entirely different course. Or perhaps never
have been written at all. As you find the knowledge, share the knowledge. This book will help
get you started.
• Chapter 1 will discuss briefly the history of DHTML and Ajax in general. You’ll get a
chance to look at some real-world examples of Ajax at work, so that you can get an idea
of wher
e the industry is leading with dynamic web development.
• Chapter 2 will be a short primer on the JavaScript language. A majority of the scripting
concepts that will be used throughout the book are detailed here.
• Chapter 3 is a detailed discussion on the heart of Ajax: the XmlHttpRequest object.
• Chapters 4 and 5 discuss the role of Ajax in an n-tiered environment and the definition
of Ajax as it relates to the world of rich clients.
• Chapter 6 is an examination of cascading style sheets and the Document Object Model.
The DOM and CSS are two very key components to Ajax, and this chapter is vital to the
book as a whole.
xix
6706fmfinal.qxd 6/20/06 3:40 PM Page xix
• Chapter 7 discusses the existence and details of various other Ajax entities out on the
w
eb. Should your future endeavors fall on non NET environments, this chapter will
help you to seek out a comparative solution.
• Chapter 8 is an in-depth look at Jason Diamond’s Anthem library. We’ll be using his
product in a majority of the sample applications that you’ll be working through.
• Chapter 9 takes a cursory look at using Ajax with .NET web services.
• Chapters 10 through 13 are application-building-centric chapters. You’ll have an
opportunity to build Ajax websites that mimic some of the more popular technologies
in the spotlight: tagging, type-ahead, and dynamic mapping.
• Chapter 14 will be an introduction to .NET 2.0 Web Parts and how the dynamic library
can work within the constraints of the part.

• Chapters 15 through 19 will deal exclusively with the usage aspect of Ajax. How we
design, debug, monitor, and scale the projects that we build will be the key concepts
covered.
• Chapter 20 will wrap up the book with a detailed look at Microsoft’s Atlas. We’ll build a few
applications to demonstrate some of the central functionality that the library provides.
Ajax Requirements
I’d like to discuss a few of the various requirements that Ajax may impose upon your develop-
ment realm.
Browser Support
A key component of Ajax technology is the XmlHttpRequest object, and without it any form of
communication with the server would be nearly impossible. It wasn’t until Internet Explorer
version 5 was released that the XmlHttpRequest capability was available to developers. Unfor-
tunately, it was only functional within the IE browser. However, more and more companies/
open source communities are embracing the object, and subsequently the XmlHttpRequest
object has become widely compatible with modern browsers:
• Internet Explorer 5.0 and above
• Firefox 1.0 and above

S
afari 1.2 and above
• Opera 7.6 and above
• Konqueror

N
etscape 7.0 and abo
v
e
JavaScript Enabled
One of the criticisms surrounding Ajax.NET technology is that unilateral support may be
interrupted by those users who have disabled JavaScript or ActiveX functionality.

■INTRODUCTIONxx
6706fmfinal.qxd 6/20/06 3:40 PM Page xx
By default, most browsers will allow ActiveX and JavaScript to operate correctly. However,
s
ome third-party antivirus and web security software may limit the browser’s ability to render
Ajax.NET applications. Repairing the settings within Internet Explorer is as simple as modify-
ing the selections under the Security tab of Internet Options.
Development Tools
You bought this book because you’re keenly interested in developing Ajax.NET applications
within the .NET Framework. Our obvious choice for .NET development is the Microsoft Visual
Studio product collection. While this book centers primarily on ASP.NET 2.0 and Visual Studio
2005, you can just as easily port a majority (not including the Atlas stuff, of course) of this
book to the 2003 edition. The technology is virtually unchanged across the platforms when
dealing with the XmlHttpRequest object.
If you do not have Visual Studio 2005, I encourage you to visit the Microsoft site and
download the (currently) free version of Visual Web Developer 2005 (VWD). It’s an awesome
application, and you can’t beat the price.
VWD can definitely get you started on the ASP.NET 2.0 road, but ultimately you’ll want to
pick up the Visual Studio package. VWD is lacking in some core components that you’ll defi-
nitely need long term:
• No mobile device support
• Missing full MSDN help file
• No Class Designer
• Lack of deployment tools
• No source code control
These are just a few of the differences between the two products, but they’re enough to
justify purchasing the full product later.
Programming Languages
Once you’ve installed a development tool, you’ll want to decide on the language in which you’ll
develop. The code within this book is listed in C#, but can be easily ported over to Visual Basic

.NET. I won’t editorialize the ongoing debate on which is better. I will say that I was in total
agreement with something that Rocky Lhotka said at a .NET users group meeting: “If you’re not
learning and using both, then you’re selling yourself short.” Well put, Rocky!
Ajax.NET Library
As Ajax grows in popularity, so does the volume of Ajax.NET interface libraries available across
the web
. Essentially these libraries take the complexity out of utilizing XmlHttpRequest and
r
ender simple methods for client- and ser
v
er
-side usage
.
You could, of course, skip the imple-
mentation of an Ajax.NET library and code the XmlHttpRequest processes yourself. However,
as many dev
elopers have said, “Why reinvent the wheel?”
■INTRODUCTION
xxi
6706fmfinal.qxd 6/20/06 3:40 PM Page xxi
There are many libraries out there, as I’ve said before, but two stand out from the rest:

Michael Schwarz’s Ajax.NET Professional ( A popu-
l
ar and effective toolset. It’s updated and supported by Michael and a newly established
Google group (
Keep in mind that this
library makes use of HTTPHandlers and for some that could create some issues. I’ve
had the opportunity to use this on a work-related project (
www.spout.com) and was

quite pleased with its transparent ability to “just work.”

Jason Diamond’s Anthem.NET (e/weblog/): Formerly referred
to as
My Ajax.NET, Jason’s class library is compact and does not use HTTPHandlers. It’s a
single class file that can be implemented seamlessly into any ASP.NET project. This book
will make use of this particular library, simply for its conciseness and ease of learning.
The Source Code for This Book
If you travel over to the Apress website (www.apress.com), you’ll find the sample applications
for each of the corresponding chapters. Click the Source Code link and search for
Pro Ajax and
the .NET 2.0 Platform
. You’ll find that the code has been organized in chapter format for easy
location and execution.
Summary
I’m confident that working through the examples and illustrations contained within will leave
you well prepared for some really cool development work. It truly is an exciting time in the web
development world, and I hope that your journey through it is as fascinating as mine has been.
Thank you for buying the book! I hope it’s as much fun to read as it was to write!
■INTRODUCTIONxxii
6706fmfinal.qxd 6/20/06 3:40 PM Page xxii
Ajax Concepts
Everyone has an opinion on what constitutes Ajax technology. The term Ajax, coined by
Jesse James Garrett of Adaptive Path, is actually an acronym for Asynchronous JavaScript
And XML. However, for some, simply modifying a web page through CSS categorically indi-
cates Ajax in use. Some say that Ajax is simply HTML with an inherent ability to avoid
postbacks. Others would passionately argue that Ajax technology is the explicit access of
server-side code from within the context of client-side scripts. So who’s correct? Everyone!
Ajax is a collaboration of technologies rather than a rigid enforcement of a particular tool or
methodology. Ajax for the .NET Framework, an implementation of Ajax for the ASP.NET plat-

form, marries CSS, HTML, JavaScript, and the .NET Framework to produce dynamic web
content. However, this collaborative effort was not born in a day. It may surprise many to
find out how this “new” technology has surfaced as a powerhouse of dynamic web con-
tent. Before we jump into coding and conventions, let’s take a look at the relatively short
history of web development.
PART 1
■ ■ ■
6706ch01final.qxd 6/20/06 2:48 PM Page 1
6706ch01final.qxd 6/20/06 2:48 PM Page 2

×