professional asp.net 4.5 in c# and vb - Pdf 20

www.it-ebooks.info
ffirs.indd iffirs.indd i 4/10/2013 9:08:25 PM4/10/2013 9:08:25 PM
www.it-ebooks.info
PROFESSIONAL ASP.NET 4.5 IN C# AND VB
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xliii
 PART I ASP.NET FUNDAMENTALS
CHAPTER 1
One ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CHAPTER 2 HTML5 and CSS3 Design with ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . .17
CHAPTER 3
ASP.NET Web Forms Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
PART II CONTROLS
CHAPTER 4
ASP.NET Server Controls and Client-Side Scripts . . . . . . . . . . . . . . . . . 103
CHAPTER 5
ASP.NET Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
CHAPTER 6
Validation Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
CHAPTER 7
User and Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
 PART III DATA ACCESS
CHAPTER 8
Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
CHAPTER 9
Model Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
CHAPTER 10
Querying with LINQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .371
CHAPTER 11
Entity Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
CHAPTER 12

CHAPTER 27 Developing Websites with Mobile in Mind . . . . . . . . . . . . . . . . . . . . . . 1001
 PART VIII APPLICATION CONFIGURATION AND DEPLOYMENT
CHAPTER 28 Confi guration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027
CHAPTER 29 Debugging and Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075
CHAPTER 30 Modules and Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1105
CHAPTER 31 Asynchronous Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121
CHAPTER 32 Building Global Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1135
CHAPTER 33 Packaging and Deploying ASP.NET Applications . . . . . . . . . . . . . . . . .1163
 PART IX ADDITIONAL ASP.NET TECHNOLOGIES
CHAPTER 34 ASP.NET MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1187
CHAPTER 35 ASP.NET Web Pages and Razor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1215
 PART X APPENDIXES
APPENDIX A Migrating Older ASP.NET Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1239
APPENDIX B COM Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247
APPENDIX C ASP.NET Ultimate Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1257
APPENDIX D Administration and Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1269
APPENDIX E Dynamic Types and Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1295
APPENDIX F ASP.NET Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1305
APPENDIX G Visual Studio Extensibility with NuGet . . . . . . . . . . . . . . . . . . . . . . . . . . 1309
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333
ffirs.indd iiffirs.indd ii 4/10/2013 9:08:26 PM4/10/2013 9:08:26 PM
www.it-ebooks.info
PROFESSIONAL
ASP.NET 4.5 in C# and VB
ffirs.indd iiiffirs.indd iii 4/10/2013 9:08:26 PM4/10/2013 9:08:26 PM
www.it-ebooks.info
ffirs.indd ivffirs.indd iv 4/10/2013 9:08:26 PM4/10/2013 9:08:26 PM
www.it-ebooks.info
PROFESSIONAL
ASP.NET 4.5 in C# and VB

motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold
with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services.
If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-
lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to
in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or Web site may provide or recommendations it may make. Further, readers
should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was
written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with stan-
dard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such
as a CD or DVD that is not included in the version you purchased, you may download this material at http://book
support.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2013933610
Trademarks: Wiley, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or
registered trademarks of John Wiley & Sons, Inc. and/or its af liates, in the United States and other countries, and may
not be used without written permission. All other trademarks are the property of their respective owners. John Wiley &
Sons, Inc., is not associated with any product or vendor mentioned in this book.
ffirs.indd viffirs.indd vi 4/10/2013 9:08:26 PM4/10/2013 9:08:26 PM
www.it-ebooks.info
To my loving wife, Lisa, and our four awesome
children.
—J N. G
I would like to dedicate this book with the following
quote, to my mother who has been instrumental in my
upbringing and is an integral part of my life. Abraham
Lincoln said, “All that I am, or hope to be, I owe to
my angel mother.”
—P R

to various open source projects, is a Microsoft ASP.NET MVP and an ASPInsider, and co-author of several
developer certi cations. You can follow him on Twitter at @chwenz.
PRANAV RASTOGI is a member of the Microsoft ASP.NET product team and is based in
Seattle. Over the past years, Pranav has worked on a variety of areas such as ASP.NET
Web Forms, Dynamic Data, and more recently ASP.NET SignalR. He is passionate about
understanding web developer woes with the Microsoft stack and helps champion tools,
packages, or libraries that will enhance the web development experience on the Microsoft
stack. Pranav is also a regular speaker on a variety of ASP.NET related topics at various
worldwide conferences. He blogs about his experiences at />pranav_rastogi/
. Before joining Microsoft, Pranav graduated from the University Of
Florida with a masters in Computer Science. 
Pranav is also a food junkie who sometimes works as a Chef de Cuisine at home. He is an adventure seeker
and can be often found backpacking in the wilderness. In this spare time Pranav regularly practices his bar-
tending skills on his friends. If you know anyone who is looking to throw a party and needs a bartender,
then get in touch with him. You can follow Pranav on Twitter at
@rustd.
ffirs.indd ixffirs.indd ix 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
TODD MIRANDA is an active proponent of .NET technologies and software craftsman-
ship as a whole. He has been developing on various platforms for over 20 years and has
been involved with .NET since it was previewed in 2000. He has worked with many of
the .NET platforms but focuses primarily on ASP.NET. He is the owner of NxtDimension
Solutions and provides consulting and training on the Microsoft stack. As a Microsoft
MVP, Todd works closely with Microsoft. He is the co-founder of the Birmingham .NET
User Group and remains active in the development community. He has recorded hundreds
of online training videos on Microsoft development topics including security, JavaScript,
Silverlight, WPF, Expression, and ASP.NET. He is an INETA speaker and regularly
presents at user groups, community events, and technical conferences. You can follow
Todd on Twitter @tmiranda.
SCOTT HANSELMAN is a web developer who has been blogging at http://hanselman

ffirs.indd xffirs.indd x 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
JEFFERY TAY has been developing and designing .NET solutions since 2002, specializing in solutions
for the education and medical sectors. He was awarded Microsoft Most Valuable Professional for the last
3 years. He has experience in Java and most Microsoft technologies such as Silverlight, SQL Server, and
Windows Server. He is an associate director at the National University of Singapore where he leads a team
that manages the university’s Learning Management System and comes up with new solutions where the use
of IT can enhance teaching. You can reach Jeffery at
DEEPAK VERMA has been developing and designing web solutions for the last 10 years. During these years,
Deepak has been involved in technologies such as Flash Scripting, Flex, ColdFusion, Silverlight, Java, and
PHP and now is mostly working on Microsoft stack. He is currently working as a Software Development
Engineer in Test for Microsoft. At Microsoft he has contributed to Visual Studio Dynamic data tooling,
multi-targeting, Razor editor and tooling, Azure SDK for Java, PHP & .NET, Visual Studio HTML and
CSS editors, Azure Mobile Services, and NuGet. He lives in Redmond, Washington, with his wife, Madhu,
and children, Adya and Kian. You can reach him at

ffirs.indd xiffirs.indd xi 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
ffirs.indd xiiffirs.indd xii 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
ACQUISITIONS EDITOR
Mary James
SENIOR PROJECT EDITOR
Kevin Kent
TECHNICAL EDITORS
Ken Cox
Bipin Joshi
John Petersen
Je ery Tay
Deepak Verma

COVER DESIGNER
Elizabeth Brooks
COVER IMAGE
© Marilyn Nieves / iStockphoto
BACKGROUND
© PhotoAlto Images/Fotosearch
CREDITS
ffirs.indd xiiiffirs.indd xiii 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
ffirs.indd xivffirs.indd xiv 4/10/2013 9:08:27 PM4/10/2013 9:08:27 PM
www.it-ebooks.info
ACKNOWLEDGMENTS
I’D LIKE TO THANK the time and dedication of the team at Wrox Press and John Wiley & Sons. Without
their support, this book would not be possible. Thanks to Scott Hunter, Scott Hanselman, Damian
Edwards, and the rest of the ASP.NET team for their current leadership to bring ASP.NET 4.5 to market.
Thanks to Scott Guthrie, Steve Smith, and Rob Howard for allowing me to join the ASPInsiders program
and helping me get my content off the ground. Thanks to all of the ASPInsiders and Microsoft MVPs for
their support over the years. Thanks to Frank Sorokach in allowing me to spend the time necessary to get
my development career off the ground. Thanks to Louis Cesare and Sean Higgins for supporting my com-
munity initiatives and giving me time when I’ve needed to provide feedback to the ASP.NET team. Thanks
to Luzerne County Community College and Penn State University for allowing our user group to prosper in
Northeastern Pennsylvania. Finally, thanks to my family, speci cally my parents, Deb and Tom Gaylord; my
grandparents; my aunts and uncles; my wife, Lisa; and my children for their support. It’s not easy writing a
book and they’ve certainly understood the time and dedication needed to get this book to ship.
—J N. G
EVERY BOOK IS A TEAM EFFORT with all the editors (acquisition, development, technical, etc.) involved,
but with this title, the authors are quite a large team, too! So thank you to Jason, Pranav, Scott, and Todd, it
has been an honor working with you. Also we are indebted to the authors of the previous editions, to every-
one involved at Wiley, and to our tech editors.
About 7 years ago, I was working on another book for the Wrox imprint of Wiley, and promised Yvonne

Integrating the Ecosystem Is Easy 9
Real-World Example 11
How Do You Benefi t? 14
ASP.NET Makes Getting Started Easy 14
ASP.NET Supports the Web Ecosystem 14
ASP.NET Makes Finding, Adding, and Updating Lego
Blocks to Your Site Easy 15
ASP.NET Helps You Apply Concepts from One Framework to Another 15
ASP.NET Moves as Fast as the Web 15
Summary 16
CHAPTER 2: HTML5 AND CSS3 DESIGN WITH ASP.NET 17
Caveats 18
HTML5 Overview 18
New Elements, Attributes, and Values in HTML5 19
Using the New HTML5 Markup 22
New APIs in HTML5 23
CSS3 Overview 24
Creating Style Sheets 25
CSS Rules 27
CSS Inheritance 34
Element Layout and Positioning 35
New Features in CSS3 41
HTML and CSS Compatibility 45
Working with HTML and CSS in Visual Studio 46
ftoc.indd xviiftoc.indd xvii 4/10/2013 9:09:22 PM4/10/2013 9:09:22 PM
www.it-ebooks.info
xviii
CONTENTS
Working with CSS in Visual Studio 46
Styling ASP.NET Controls 48

App_LocalResources Folder 83
App_WebReferences Folder 83
App_Browsers Folder 83
Compilation 83
Build Providers 87
Using the Built-In Build Providers 88
Using Your Own Build Providers 89
Global.asax 93
Working with Classes through Visual Studio 2012 96
Summary 99
ftoc.indd xviiiftoc.indd xviii 4/10/2013 9:09:23 PM4/10/2013 9:09:23 PM
www.it-ebooks.info
xix
CONTENTS
PART II: CONTROLS
CHAPTER 4: ASP.NET SERVER CONTROLS
AND CLIENT-SIDE SCRIPTS 103
ASP.NET Server Controls 104
Types of Server Controls 104
Building with Server Controls 105
Working with Server Control Events 107
Applying Styles to Server Controls 108
HTML Server Controls 111
Looking at the HtmlControl Base Class 112
Looking at the HtmlContainerControl Class 113
Looking at All of the HTML Classes 113
Using the HtmlGenericControl Class 114
Identifying ASP.NET Server Controls 115
Manipulating Pages and Server Controls
with JavaScript 117

How to Determine Whether Check Boxes Are Checked 143
Assigning a Value to a Check Box 143
Aligning Text around the Check Box 144
The CheckBoxList Server Control 144
The RadioButton Server Control 146
The RadioButtonList Server Control 148
Image Server Control 149
Table Server Control 151
The Calendar Server Control 153
Making a Date Selection from the Calendar Control 153
Choosing a Date Format to Output from the Calendar 154
Making Day, Week, or Month Selections 155
Working with Date Ranges 155
Modifying the Style and Behavior of Your Calendar 157
AdRotator Server Control 160
The Xml Server Control 161
Panel Server Control 162
The PlaceHolder Server Control 164
BulletedList Server Control 165
HiddenField Server Control 171
FileUpload Server Control 172
Uploading Files Using the FileUpload Control 172
Giving ASP.NET Proper Permissions to Upload Files 175
Understanding File Size Limitations 176
Uploading Multiple Files from the Same Page 177
Placing the Uploaded File into a Stream Object 180
Moving File Contents from a Stream Object to a Byte Array 181
MultiView and View Server Controls 181
Wizard Server Control 185
Customizing the Side Navigation 186

Creating User Controls 232
Interacting with User Controls 234
Loading User Controls Dynamically 235
Server Controls 240
Server Control Projects 240
Control Attributes 244
Control Rendering 245
Styling HTML 251
Adding Client-Side Features 253
Browser Capabilities 261
Using ViewState 263
Raising Postback Events 267
Handling Postback Data 270
Composite Controls 273
Templated Controls 275
Design-Time Experiences 279
Summary 296
PART III: DATA ACCESS
CHAPTER 8: DATA BINDING 299
Data Source Controls 299
SqlDataSource Control 301
ftoc.indd xxiftoc.indd xxi 4/10/2013 9:09:23 PM4/10/2013 9:09:23 PM
www.it-ebooks.info
xxii
CONTENTS
AccessDataSource Control 307
LinqDataSource Control 307
EntityDataSource Control 307
Using the QueryExtender for Complex Filters 309
XmlDataSource Control 310

Extending Model Binding 363
Custom Value Providers 363
Custom Model Binders 365
Custom ModelDataSource 367
Summary 369
ftoc.indd xxiiftoc.indd xxii 4/10/2013 9:09:23 PM4/10/2013 9:09:23 PM
www.it-ebooks.info
xxiii
CONTENTS
CHAPTER 10: QUERYING WITH LINQ 371
LINQ to Objects 372
Understanding Traditional Query Methods 372
Replacing Traditional Queries with LINQ 376
Grouping Data Using LINQ 384
Using Other LINQ Operators 385
Making LINQ Joins 386
Paging Using LINQ 387
LINQ to XML 388
A Simple LINQ to XML Example 389
Joining XML Data 392
LINQ to SQL 393
Using the O/R Mapper 393
Accessing and Querying Data 395
Using Other SQL Query Methods 399
Making Insert, Update, and Delete Queries through LINQ 401
LINQ to Entities 405
Creating an Entity Framework Data Model 406
Accessing Data 406
Writing LINQ Queries 407
Summary 409


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status