Programming Microsoft ASP.NET 4
Dino Esposito
Copyright 2011
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) 936-7329. If you need support related to this book, e-mail Microsoft Press Book Support at .
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property 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.
This book expresses the authors views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Microsoft Press
Acknowledgments
As is usual for a book, the cover of this book shows only the name of the author, but in no way can an author produce a book all alone. In fact, a large ensemble of people made this book happen. First, I want to thank Devon Musgrave for developing the idea and scheduling new books for me to author at an amazingly quick pace for the next two years!
Next comes Roger LeBlanc , whom Ive had the pleasure to have as a copy editor on previous books of mineincluding the first edition of this Programming ASP.NET book (Microsoft Press, 2003). This time, Roger assisted me almost every daynot just as the copy editor, but also as the development manager. I dare to say that as my English gets a little bit better every year, the amount of copy editing required does not amount to much for a diligent editor like Roger. So he decided to take on extra tasks.
In the middle of this project, I had to take a short break to have back surgery. The surgery increased the number of lengths I could swim and improved my tennis game, especially the penetration of my first serve and my top-spin backhand, but it put a temporary stop to my progress on the book. As a result, Roger and I had to work very hard to get the book completed on a very tight schedule.
Steve Sagman handled the production end of the bookthings like layout, art, indexing, proofreading, prepping files for printing, as well as the overall project management. Here, too, the tight schedule required a greater effort than usual. Steve put in long days as well as weekends to keep everything on track and to ensure this edition equals or exceeds the high standards of previous editions.
Scott Galloway took the responsibility of ensuring that this book contains no huge technical mistakes or silly statements. As a technical reviewer, Scott provided me with valuable insights, especially about the rationale of some design decisions in ASP.NET. Likewise, he helped me understand the growing importance JavaScript (and unobtrusive JavaScript) has today for Web developers. Finally, Scott woke me up to the benefits of Twitter, as tweeting was often the quickest way to get advice or reply to him.
To all of you, I owe a monumental Thank you for being so kind, patient, and accurate. Working with you is a privilege and a pleasure, and it makes me a better author each time. And I still have a long line of books to author.
My final words are for Silvia, Francesco, and Michela, who wait for me and keep me busy. But Im happy only when Im busy.
Dino
Introduction
In the fall of 2004, at a popular software conference I realized how all major component vendors were advertising their ASP.NET products using a new wordAjax. Only a few weeks later, a brand new module in my popular ASP.NET master class made its debutusing Ajax to improve the user experience. At its core, Ajax is a little thing and fairly old tooas I presented the engine of it ( XmlHttpRequest ) to a C++ audience at TechEd 2000, only four weeks before the public announcement of the .NET platform.
As emphatic as it may sound, that crazy little thing called Ajax changed the way we approach Web development. Ajax triggered a chain reaction in the world of the Web. Ajax truly represents paradigm shift for Web applications. And, as the history of science proves, a paradigm shift always has a deep impact, especially in scenarios that were previously stable and consolidated. We are now really close to the day we will be able to say the Web without feeling the need to specify whether it contains Ajax or not. Just the Webwhich has a rich client component, a made-to-measure layer of HTTP endpoints to call, and interchangeable styles.
Like it or not, the more we take the Ajax route, the more we move away from ASP.NET Web Forms. In the end, its just like getting older. Until recently, Web Forms was a fantastic platform for Web development. The Web, however, is now going in a direction that Web Forms cant serve in the same stellar manner.
No, you didnt pick up the wrong book, and you also did not pick up the wrong technology for your project.
Its not yet time to cease ASP.NET Web Forms development. However, its already time for you to pay a lot more attention to aspects of Web development that Web Forms specifically and deliberately shielded you from for a decadeCSS, JavaScript, and HTML markup.
In my ASP.NET master class, I have a lab in which I first show how to display a data-bound grid of records with cells that trigger an Ajax call if clicked. I do that in exactly the way one would do itas an ASP.NET developer. Next, I challenge attendees to rewrite it without inline script and style settings. And yesa bit perverselyI also tell anyone who knows jQuery not to use it. The result is usually a thoughtful and insightful experience, and the code I come up with gets better every time. ASP.NET Web Forms is not dead, no matter what ASP.NET MVCthe twin technologycan become. But its showing signs of age. As a developer, you need to recognize that and revive it through robust injections of patterns, JavaScript and jQuery code, and Ajax features.
In this book, I left out some of the classic topics you found in earlier versions, such as ADO.NET and even LINQ-to-SQL. I also reduced the number of pages devoted to controls. I brought in more coverage of ASP.NET underpinnings, ASP.NET configuration, jQuery, and patterns and design principles. Frankly, not a lot has changed in ASP.NET since version 2.0.
Because of space constraints, I didnt cover some rather advanced aspects of ASP.NET customization, such as expression builders, custom providers, and page parsers. For coverage of those items, my older book Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics (Microsoft Press, 2006) is still a valid reference in spite of the name, which targets the 2.0 platform. The new part of this book on principles of software design is a compendium of another pretty successful book of mine (actually coauthored with Andrea Saltarello)Microsoft .NET: Architecting Applications for the Enterprise (Microsoft Press, 2008).
Who Should Read This Book?
This is not a book for novice developers and doesnt provide a step-by-step guide on how to design and code Web pages. So the book is not appropriate if you have only a faint idea about ASP.NET and expect the book to get you started with it quickly and effectively. Once you have grabbed hold of ASP.NET basic tasks and features and need to consolidate them, you enter the realm of this book.