Beginning jQuery 2 for ASP.NET Developers - Bipin Joshi.pdf

(10147 KB) Pobierz
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xv
About the Technical Reviewer �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xvii
Acknowledgments �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xix
Introduction �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xxi
■
Chapter 1: The JavaScript You Need to Know �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½1
■
Chapter 2: A First Look at jQuery �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½33
■
Chapter 3: ASP�½NET Controls and jQuery Selectors �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½63
■
Chapter 4: Event Handling �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½103
■
Chapter 5: DOM Manipulation and Dynamic Content�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½135
■
Chapter 6: Traversal and Other Useful Methods �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½157
■
Chapter 7: Effects and Animations �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½179
■
Chapter 8: Ajax Techniques �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½193
■
Chapter 9: Creating and Using Plugins �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½231
■
Chapter 10: jQuery UI and jQuery Mobile �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½255
■
Chapter 11: Useful jQuery Recipes for ASP�½NET Applications �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½281
■
Appendix: Learning Resources �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½301
Index �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½303
v
Introduction
Welcome to the exciting world of jQuery! If you’re an ASP.NET developer looking to turbocharge your ASP.NET
applications with jQuery, you picked the right book. Modern web applications leverage browsers’ resources through
client-side scripting. Although JavaScript is a
de facto
standard as far as client-side scripting is concerned, there are
several libraries built on top of JavaScript that help developers accomplish their job quickly and easily. jQuery is one
of the most popular JavaScript libraries available today. If you want to develop Ajax-driven, dynamic, and
cross-browser web applications using ASP.NET, understanding jQuery is an invaluable skill.
While using jQuery in ASP.NET Web Forms and ASP.NET MVC projects, you need to combine the power of
jQuery with server controls, controllers, services, and APIs. It is crucial to understand how jQuery can be used
effectively in combination with ASP.NET features and technologies.
To that end, this book teaches you how to harness the power of the jQuery library in your ASP.NET Web Forms
and MVC applications. It helps you understand the foundations of jQuery from the perspective of an ASP.NET
developer in a clear, step-by-step way, so that you can quickly ensure you have this invaluable skill under your belt.
Who This Book Is For
This book is for ASP.NET web developers who want to tap the power of jQuery in their existing or new web
applications. This book doesn’t teach you ASP.NET features. I assume that you’re already comfortable working with
ASP.NET and doing web application development in general.
All the code samples discussed in this book use C# as the server-side programming language, so you should
also know C#. Although no prior knowledge of jQuery is expected, I assume that you’re familiar with the basics of
JavaScript.
The examples illustrated throughout the book use SQL Server and Entity Framework. Although you need not
have a detailed understanding of these technologies, you should at least be familiar with them.
The book uses Visual Studio as the development tool. You should know how to work with Visual Studio to
perform basic tasks such as creating projects and debugging code.
Software Required
To work through the examples in this book, you need the following software:
•
•
•
•
Visual Studio 2013
SQL Server 2012
jQuery, jQuery UI, and jQuery Mobile library files
Web browsers: Internet Explorer 9+, Firefox, Chrome, Opera, and Safari
Although I used Visual Studio Ultimate 2013 to develop the book’s examples, most of the examples can also be
developed using Visual Studio Express 2013 for Web.
xxi
■
IntroduCtIon
All the data-driven examples were developed using SQL Server 2012 Express Edition. I use the Northwind sample
database in many examples, and I suggest you install it. You can download the Northwind database and its script from
the MSDN downloads web site.
I used jQuery 2.0.3 to write the examples presented in this book. You should consider downloading the latest
versions of jQuery, jQuery UI, and jQuery Mobile from their official web sites.
It’s always a good idea to test the client scripts you write in all the major browsers. So you might consider
installing the latest versions of Internet Explorer, Firefox, Chrome, Opera, and Safari.
How This Book Is Structured
This book is organized into 11 chapters and one appendix. Here’s a quick overview:
•
•
Chapter 1
gives you a quick recap of JavaScript programming. You can brush up on your
JavaScript skills before taking on jQuery.
Chapter 2
gives you a peek into jQuery. You learn the basics, such as downloading and
installing jQuery on your machine. You also develop a simple application in ASP.NET Web
Forms and MVC.
Chapter 3
gives you a detailed understanding of jQuery selectors. You learn to match DOM
elements using powerful and flexible selectors. This chapter also details techniques to deal
with server controls while selecting them in the jQuery code.
Chapter 4
teaches you one of the most commonly used features: event handling. It covers
commonly used events such as window, keyboard, and mouse events. Some advanced concepts
relating to event handling, such as passing custom data to the event handler, are also covered.
Chapter 5
is about DOM manipulation using jQuery. Topics covered include applying CSS
styles, working with attributes, and manipulating DOM elements.
Chapter 6
covers DOM navigation and filtering techniques, including tree traversal, iterating,
searching, working with custom data attributes, and more.
Chapter 7
teaches you how to apply jQuery effects and animations to Web Form controls
and page elements. You learn to apply fancy effects such as fade-in, fade-out, slide-up and
slide-down. You also learn to apply custom animation effects to page elements.
Chapter 8
covers an important topic: Ajax techniques offered by jQuery. This chapter discusses
how ASMX web services, WCF services, MVC action methods, and the Web API can be called
from the jQuery code. It also discusses the JSON format and its use in Ajax communication.
Chapter 9
discusses plugins—a technique to extend the jQuery core. You can develop plugins
to enhance and extend the core functionality offered by jQuery. The chapter discusses the
steps involved in building a plugin and gives you some recommendations to be followed
during the process.
Chapter 10
gives you an overview of jQuery UI and jQuery Mobile. jQuery UI provides various
widgets that you can add to ASP.NET web applications to provide professional user interface
elements such as dialogs, menus, accordions, and sliders. jQuery Mobile helps you develop
web applications targeted at mobile devices.
Chapter 11
presents a few recipes that you will find useful in real-world applications. The
recipes covered include implementing Ajax-based paging, client-side sorting, file upload,
autocomplete text box, and cascading drop-down lists.
The Appendix lists some jQuery learning resources.
•
•
•
•
•
•
•
•
•
•
xxii
Zgłoś jeśli naruszono regulamin