ASP.NET 3.5 For Dummies - Ken Cox - E-Book

ASP.NET 3.5 For Dummies E-Book

Ken Cox

0,0
21,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Did you volunteer to create a Web site for the softball team? Is it time to take your small business to the next level and let your customers shop online? Well, you can relax! ASP.NET 3.5 makes creating a dynamic site faster and cleaner than ever before, and ASP.NET 3.5 For Dummies makes it easier. First, you'll get an introduction to all the tools and terminology you need to understand ASP.NET. If you've used earlier versions of ASP.NET and Visual Web Developer, you can probably skip that part and jump right into what's new in 3.5. You'll make friends with LINQ and SQL, create sites in Visual Web Developer 2008 Express, and much more. Before you know it, you'll discover how to: * Integrate data, track shopping cart contents, and whisk away bugs * Create user interfaces with easy navigation * Use the ListView control for sophisticated formatting * Write LINQ queries * Add a table to a database * Create an event handler * Take advantage of the drag 'n' drop feature that lets you write less code * Put all the features to work to develop dynamic Web applications The softball team is going to love that Web site, and your customers might enjoy shopping on your site so much that you'll have to expand your business to fill all the orders! We can't promise that, of course, but we're pretty sure that ASP.NET 3.5 For Dummies will make creating Web sites easier and a lot more fun.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 459

Veröffentlichungsjahr: 2011

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



ASP.NET 3.5 For Dummies

by Ken Cox

ASP.NET 3.5 For Dummies®

Published byWiley Publishing, Inc.111 River St.Hoboken, NJ 07030-5774www.wiley.com

Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201)748-6011, fax (201)748-6008, or online at http://www.wiley.com/go/permissions.

Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates 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. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional 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 publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website 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 Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites 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 U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

For technical support, please visit www.wiley.com/techsupport.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2008920596

ISBN: 978-0-470-19592-5

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

About the Author

Ken Cox is a Canadian writer and programmer. He earned a Bachelor of Applied Arts (BAA) degree in Radio and Television Arts from Ryerson University in Toronto, which led to a 25-year career as an on-air journalist in Toronto and Quebec City. He contributed reports to local stations CFRB and CJAD as well news networks such as CBC, CBS, NBC, and the BBC. His claim to fame is that he has chatted in English and French with Queen Elizabeth II of England.

Ken’s passion for computers and things high-tech led him to earn a college certificate in Technical Communications. He then pursued a second career as a technical writer and information developer with companies including Nortel in Toronto. His documentation has won numerous awards from the Society for Technical Communication.

As the Internet and World Wide Web became popular, Ken started tinkering with Web pages. Despite having no formal training in programming, he found himself part of the earliest beta of a ground-breaking Microsoft product that was code-named Denali. Denali became Active Server Pages (ASP) 1.0, which later evolved into ASP.NET with Visual Studio and Visual Web Developer as its primary development tool.

Microsoft has awarded Ken its coveted Most Valuable Professional (MVP) status each year since 1998 in recognition of his volunteer assistance to users in online communities such as the ASP.NET newsgroups.

He currently works as a contract Web applications consultant, programming writer, technical reviewer, author, and as a contributing editor for Visual Studio Magazine.

Ken, his wife Vilia, and their dog Goldie (a GoldenDoodle) spend spring, summer, and fall at a peaceful lakefront home in a forest in Nipissing Township, Ontario, Canada. They winter in Victoria, British Columbia.

Dedication

To my wife, Vilia, for encouraging me to pursue my dreams.

Author’s Acknowledgments

Thanks to Acquisitions Editor Katie Feltman for showing faith in my abilities by offering me a chance to write a book of my own on a topic I love. To Rebecca Senninger and Blair Pottenger, the project editors: thanks for being my air traffic controllers, troubleshooters, advisors, and all-round publishing resources. Thanks also to my technical reviewer and fellow MVP, Mark Rae, for catching my slips and making valuable suggestions for a better book. The mistakes that remain are mine.

To my wife, Vilia: You’ve been a tremendous support for over 37 years. This book is just another example of how I couldn’t manage without your love and guidance. You’ve always encouraged me to follow my dreams. I’m a lucky guy to have found you.

Finally, a shake of the paw and a “bikkie” (dog biscuit) for our dog Goldie. Your muzzle nudges and refusal to be ignored guarantee restorative breaks outdoors at 12:30 p.m., 5:30 p.m., and 10:30 p.m. every day, rain or shine. Okay, Goldie, go find your ball!

Publisher’s Acknowledgments

We’re proud of this book; please send us your comments through our online registration form located at www.dummies.com/register/.

Some of the people who helped bring this book to market include the following:

Acquisitions, Editorial, and Media Development

Project Editor: Rebecca Senninger

Senior Acquisitions Editor: Katie Feltman

Copy Editor: Brian Walls

Technical Editor: Mark Rae

Editorial Manager: Leah Cameron

Editorial Assistant: Amanda Foxworth

Sr. Editorial Assistant: Cherie Case

Cartoons: Rich Tennant (www.the5thwave.com)

Composition Services

Project Coordinator: Erin Smith

Layout and Graphics: Stacie Brooks, Reuben W. Davis, Alissa D. Ellet, Shawn Frazier, Christine Williams

Proofreaders: Cynthia Fields, John Greenough, Bonnie Mikkelson

Indexer: Infodex Indexing Services, Inc.

Special Help

Teresa Artman; Kelly Ewing; Virginia Sanders

Publishing and Editorial for Technology Dummies

Richard Swadley, Vice President and Executive Group Publisher

Andy Cummings, Vice President and Publisher

Mary Bednarek, Executive Acquisitions Director

Mary C. Corder, Editorial Director

Publishing for Consumer Dummies

Diane Graves Steele, Vice President and Publisher

Joyce Pepple, Acquisitions Director

Composition Services

Gerry Fahey, Vice President of Production Services

Debbie Stailey, Director of Composition Services

Contents

Title

Introduction

I Know Who I Am: Who Are You?

Less Code, More Productivity

How to Use This Book

How This Book Is Organized

What’s on the Web Sites

Icons Used in This Book

Where to Go from Here

Part I : Getting to Know ASP.NET and Visual Web Developer

Chapter 1: Understanding Microsoft’s Web Technologies

Introducing the Content-Creation Tools

Meeting the Technologies behind Web Applications

Chapter 2: Getting Up and Running

Installing Visual Web Developer Express

Finally! Creating an ASP.NET Web Page

Tweaking Your Development Environment

Working with the Toolbox

Peering into a Wall of Windows

Chapter 3: Creating a Useful ASP.NET Site

Creating the DVD Web Project

Using a SQL Server Express Database

Generating a Data-Driven Web Page

Chapter 4: Managing Data and Other CRUD

Working with Smart Tags and Designers

Enhancing the GridView Control

Introducing the FormView Control

Fixing the Page Title

Improving Performance with the AJAX Update Panel

Chapter 5: Handling User Input and Events

Accepting Data in a TextBox Control

Pushing for Choices with the RadioButton Control

Collecting RadioButtonList Controls

Checking CheckBox and CheckBoxList Controls

Using the DropDownList Control

Getting Multiple Choices from a ListBox

Understanding ASP.NET Forms

Part II : Immersing Yourself in Data

Chapter 6: Fetching and Presenting Data with SqlDataSource

Connecting to SQL Server Express

Using the SqlDataSource Control

Consuming Data with the DetailsView Control

Using Parameters in Queries

Creating a Master/Detail Page

Chapter 7: LINQ as a Data Language

Setting Up the LINQ Examples

LINQing with From, Where, and Select

Filtering with an Eye on Strings

Filtering Based on Numbers

Thoroughly Aggregating Data

Grouping, Sorting, and Making Distinct

Using LINQ to Create and Query XML

Chapter 8: Using LINQ to SQL and the LinqDataSource

Building a LINQ to SQL CRUD Page

Enhancing Usability with LinqDataSource

Filtering Data with LinqDataSource

Displaying Hierarchical Data with LINQ

Updating Data with a LINQ Query

Inserting Data with the DataContext

Chapter 9: Creating and Consuming Diverse Data

Putting an RSS Feed on a Page

Making an RSS Feed Available from Your Site

Transforming XML Data into HTML Markup

Connecting Web Applications to an Access Database

Creating a Simple Web Service

Adding a Web Reference to a Project

Creating a Page to Use the Web Service

Creating a Daylight Saving WCF Service

Creating the Service Consumer Web Form

Connecting to a WCF Endpoint

Part III : Enhancing the Interface and User Experience

Chapter 10: Common Elements: Style Sheets, Master Pages, and Skins

Deciding Where Style Rules Belong

Using the VWD Style Sheet Tools

Managing Style Rules

Using Master Pages with Slavish Devotion

Skinning Is Just What It Themes

Chapter 11: Adding Navigation with TreeView, Menu, Breadcrumb, and SiteMap

Using a Treeview on a Web Page

Building a Menu for Your Site

Adding a Breadcrumb Feature to Your Pages

Chapter 12: Web Standards, Page Layout, and Usability

Choosing an HTML Flavor

Creating Columns Using CSS Float

Reducing Load Times and Improving Performance

Meeting Accessibility Requirements

Increasing a Page’s Usability

Chapter 13: Designing the ListView and Other Templated Controls

Understanding Templated Controls

Rolling Your Own with the ListView Control

Using the DataPager with a ListView

Chapter 14: Dynamic Effects, Images, and Rollovers

Creating Rollover Effects

Creating and Displaying Graphics on the Fly

Displaying Uploaded Image Files As Thumbnails

Chapter 15: Enhancing Pages with the AJAX Control Toolkit

Introducing the AJAX Control Toolkit

Automatically Completing Data As the User Types

Helping Users Understand What to Enter

Guiding Input with a Masked Text Box

Choosing Dates with a Calendar

Positioning Content to Stay on Top

Chapter 16: Creating and Displaying Rich Content

Creating Your First Rays of Silverlight

Embedding Silverlight with the ASP.NET Silverlight Control

Displaying Rich Media with the MediaPlayer Control

Embedding Flash in an ASP.NET Page

Ensuring Accurate Rendering with PDF

Serving Word on the Web

Part IV : Tracking Users, Controlling Access, and Implementing Security

Chapter 17: Site Security Using Authentication and Membership

Understanding Authentication

Preparing a Site for Membership

Creating the Membership Database

Implementing Registration and Login

Adding an Administration Area

Applying Roles and Security

Chapter 18: Creating a Shopping Cart with Profiles

Introducing ASP.NET Profiles

Setting Up the Small Business Sample Site

Previewing the Final Web Interface

Building the Shopping Cart in Code

Updating a Web Page to Add Profile Data

Building a Page to Manage Cart Contents

Walking Through the Shopping Cart Profile

Chapter 19: Validation in Depth

Remembering User Input Is Evil

Forcing the User to Enter Something

Ensuring That a Value Is within a Range

Checking and Comparing Values

Using the RegularExpressionValidator

Validating Data with Code

Validating by Groups

Displaying a Summary of Invalid Fields

Defanging Markup for Safety

Part V : Getting the Bugs Out and Handling Runtime Errors

Chapter 20: Debugging and Tracing Pages

Setting Up an Error Page Scenario

Analyzing Design-Time Errors

Discovering Compile-Time Errors

Finding Logic Errors

Tracking Down a Runtime Error

Breaking Based on a Condition

Editing a Value during Execution

Panes to Ease the Pain

Tracing the (Mis)Steps of a Web Page

Using the Debugger Keys and Toolbar

Chapter 21: Avoiding Crashes by Handling Exceptions

Understanding Exceptions and Their Messages

Global Error Handling

Catching and E-Mailing Exceptions

Using Try...Catch in Risky Situations

Executing a Statement, Finally

Some Common Error Messages and Where to Look

Part VI : The Part of Tens

Chapter 22: Ten Tips on Deploying Your Web Application

Use the Copy Web Site Tool

Use the SQL Publishing Wizard

Copy a SQL Express Database

Fix the @#$%*& SQL Connection

Choose an ASP.NET-Friendly Host

Head Off a Serious Lack of Trust

Arrggh! It Works Fine on MY Machine!

Gather Troubleshooting Info

Precompile If You’re Code Shy

Encrypt Connection Information

Chapter 23: Ten Tips to Success with ASP.NET

Stop Bashing Your Head against a Wall

Google Is Your Friend

Read the Reference Documentation

Ask a Good Question, Get a Good Answer

Get Free Peer-to-Peer Support

Use the Starter Kits

Read the Hottest Blogs

Watch the Videos

Visit the Expert Web Sites

Use the Free Tools

: Further Reading

Introduction

Greetings! You just entered the world of ASP.NET 3.5 For Dummies. In case you weren’t told on the way in, ASP.NET is Microsoft’s technology for building dynamic, interactive, data-driven Web pages. The primary tool for creating ASP.NET sites is Visual Web Developer (VWD), which you use throughout this book.

Wait a minute! An introduction to an introduction is not only wordy and redundant, it’s superfluous and unnecessary.

I Know Who I Am: Who Are You?

My full name is Kenneth John Cox. I was born in Windsor, Ontario, Canada. I’m a former broadcast journalist (the pejorative term is spit-collector) whose hobby (long ago) was playing with computers. Somehow, I learned enough about ASP.NET to get paid for creating Web applications. When they pay you for your hobby, it sure beats working for a living!

Here’s what I assume about you, gentle reader:

You use a computer and know your way around Windows XP or Windows Vista.

You’re familiar with the World Wide Web and can connect to the Internet.

You’ve created a Web page in a tool like FrontPage or Dreamweaver and probably know some HTML markup.

You grasp basic programming concepts. The terms variable and loop don’t frighten you — but you aren’t necessarily a programmer.

You may have any number of reasons for digging into this ASP.NET book:

You volunteered to create a statistics Web site for your kid’s soccer league.

You’re putting your home-based business on the Web and need a data-driven page.

You develop Web sites on platforms like Java and PHP and want to make yourself more marketable by including Microsoft’s technology.

You’ve worked with a previous release of ASP.NET and want to get up to speed on new stuff like AJAX, LINQ, and the ListView control.

Your boss is dabbling in ASP.NET and might let you play in his sandbox if you talk a good enough game.

You collect For Dummies books and master each book’s subject before moving to the next one.

Less Code, More Productivity

When I agreed to write a book from scratch on ASP.NET 3.5, I made it clear that I wanted it to be very hands-on and task-oriented. I show you how to use Microsoft’s latest graphical tools — designers, editors, and wizards — to their best advantage. Instead of treating new features like AJAX and LINQ as separate add-ons, I integrate them into many samples.

Some professional developers would have you believe that the only effective way to create ASP.NET pages is to write the code by hand. (Do the words real men and quiche ring a bell here?) Their geeky noses have been stuck to the keyboard for so long they’ve been left behind. Microsoft has implemented powerful design-time tools in Visual Web Developer, so why not use them to be more productive?

Wherever possible, I favor the drag, drop, choose, and configure methods over typing code. Here’s why:

It’s faster. You don’t have to know — or even understand — the ins and outs of every object before creating something useful.

You create fewer bugs. Microsoft’s built-in designers write quality code based on your choices.

Pages are easier to maintain. Programmers are notorious for failing to document what their code performs and many insist that code is “self-documenting.” When you revise someone else’s code by rerunning a wizard, you spend less time playing catch-up.

That said, in many instances in this book, you do write code. Each time, I explain what the code is performing. Don’t fear being overwhelmed if you’re not a code jockey. Everyone’s a beginner at some point.

The book’s code examples are in Visual Basic .NET because Visual Basic is easy to understand, not case-sensitive, and just as powerful as C# when compiled. (Not to mention that I like VB best!)

How to Use This Book

People have different learning styles. Many are adventurers who turn to manuals only to get out of trouble. They barge into a new programming task like a deer into the forest until some grimy detail stops them in their tracks. Suddenly, progress can’t be made until they find an example or fill a knowledge gap. That’s when they scout out a likely topic in the book’s index, follow a few numbered steps, and snatch a snippet of “just-in-time” information.

In contrast to the adventurers, you might be the organized and methodical type. Perhaps you prefer to get a feel for the subject, ease into it, and analyze examples while you’re building skill and confidence. This book accommodates both approaches by including multiple hooks and starting points.

How This Book Is Organized

This book organizes the topics in parts with each part covering a different aspect of creating ASP.NET applications.

Part I: Getting to Know ASP.NET and Visual Web Developer

Part I introduces the technology and contains the information you need to start creating your first ASP.NET pages. The goal is to become comfortable enough with the terminology and tools so you relax in the rest of the book. If you’ve worked with a previous version of ASP.NET and Visual Web Developer, you might want to skim or skip Chapter 1. Chapter 2 is necessary only if you’ve never worked in a Visual Studio or Visual Web Developer environment. In Chapters 3, 4, and 5, I introduce key concepts and ensure your initial success in creating pages that work with user input.

Part II: Immersing Yourself in Data

In Part II, I walk you through the integration of data with ASP.NET pages. Chapter 6 covers the basic needs of virtually every data-driven site using the SqlDataSource control. Don’t miss Chapters 7 and 8, where I cover the new Language Integrated Query (LINQ) features. Chapter 9 digs into other data sources, such as XML and Web services.

Part III: Enhancing the Interface and User Experience

In Part III, you explore the presentation aspects of Web pages. In Chapter 10, I show you how to use the tools and techniques in VWD to create user interfaces. Every site with more than one page needs navigation, and that’s covered in Chapter 11. Chapter 12 looks at HTML standards and how to use a style sheet to divide a Web page into columns. For sophisticated formatting, Chapter 13 walks you through the versatile new ListView control. In the remaining chapters in Part III, you add dynamic effects, boost page response with AJAX, and introduce rich content, such as Microsoft Silverlight, into your pages.

Part IV: Tracking Users, Controlling Access, and Implementing Security

Part IV is largely about security and recognizing returning visitors. In Chapter 17, I show you how easy it is to secure pages by using ASP.NET’s built-in authentication and membership features. The chapter offers professional touches that users appreciate. In Chapter 18, you build an e-commerce style shopping cart by using ASP.NET’s built-in Profiles feature. Chapter 19 demonstrates ways to ensure that users — friendly or otherwise — provide your application with clean, safe, validated data.

Part V: Getting the Bugs Out and Handling Runtime Errors

Turn to the chapters in this part to figure out why a page or site isn’t behaving the way it should. Chapter 20 shows techniques for checking what’s going on deep in your app. Chapter 21 provides defenses to cope with unforeseen errors in a deployed page.

Part VI: The Part of Tens

In Chapter 22, you copy your ASP.NET pages and associated files to the Internet. The last chapter of the book points you toward helpful resources for when you’re stuck or you need to expand your expertise and investigate more complex subjects.

What’s on the Web Sites

This book has two Web sites to provide online resources. The first is the book’s official page at www.dummies.com/aspdotnet35fordummies where you can read excerpts, download the book’s source code, and fill a shopping cart with extra copies of ASP.NET 3.5 For Dummies for your friends, loved ones, and coworkers.

The second site, www.kencox.ca, is the place for book-related help. It’s my personal site (could you guess by the domain name?) with updated links to tools, forums, and resources that I discuss in this book. There’s a frequently asked questions area, a contact form, errata (hardly any!), and pictures of my dog. Don’t miss the junk drawer-like Stuff section!

Icons Used in This Book

You find a handful of useful icons in this book. Here’s what they mean:

Tips highlight a handy shortcut or help you understand something important about ASP.NET or Visual Web Developer.

This icon marks something that might trip you up the next time you encounter it.

The Technical Stuff icon alerts you to information (such as a discussion about code) that’s heavier than usual. Skip it if you want and come back when you’re ready.

Prepare to roll your eyes, smirk, or shake your head in disbelief at something that doesn’t make sense.

The Warning icon is like a yellow caution sign on the highway. By not heeding this advice, you could lose data or lead someone to think you don’t know what you’re doing.

Where to Go from Here

If you’re still reading this introduction, you’re the calm, persistent type who wants the A-to-Z story — proceed to Chapter 1. If you landed here while flitting about the book, you’re an adventurer who should try Chapter 4. Interested in LINQ? Jump now to Chapter 7 and play with some queries!

Part I

Getting to Know ASP.NET and Visual Web Developer

In this part. . .

In this part, especially in Chapter 1, you dive into the technologies that create Web sites on Microsoft’s platform. I include steps for software installation (Chapter 2) and for site creation (Chapter 3), which ensure you’re not flopping around like a fish out of water while you get your feet wet. Help! I’m drowning in metaphors!

In Chapter 4, you create data-driven ASP.NET pages — something you do often as a .NET Web developer. Building on your success, the last chapter (Chapter 5) walks you through assembling forms that accept user input with ASP.NET server controls.

It’s not unusual to feel your head swimming while you wade into a new technology. If something seems over your head, keep dog-paddling as best you can. Remember: The lifeguard also started in the shallow end of the pool — and she ended up high and dry! (Okay, I’m done.)

Chapter 1

Understanding Microsoft’s Web Technologies

In This Chapter

Exploring Microsoft’s tools for creating Web pages

Understanding the technologies behind dynamic content

Delving client-side and server-side programming

Pinpointing the roles of LINQ, DHTML, XML, XAML, and AJAX

Deciphering postbacks and page refreshes

In the beginning, the World Wide Web (WWW) was flat. It was an electronic library where academics and scientists posted dissertations and dusty data for reading with clunky, text-only browsers. With the advent of graphical browsers, the consumer-oriented Web took off. Content became vastly more colorful. Remember where you were the first time you experienced the exciting <blink> and <marquee> tags? (I bet you wish you could forget those gems!) Anyway, the Web has evolved as a rich, interactive, and personalized medium.

In the new version of Web (Web 2.0), functional pages aren’t enough. User experience (abbreviated as UX in geekspeak) is hot, and sites are cool. This chapter looks at Microsoft’s tools and technologies for creating and delivering engaging Web content.

Introducing the Content-Creation Tools

Microsoft has a range of tools for authoring Web pages that appeal to several skill levels. Some tools are more suited to Web page design, while others are more appropriate to programming.

Microsoft Office (Including Word 2007)

When Bill Gates realized that Microsoft was lagging on the Internet front, the word went out to integrate Web support into every product. As a result, you can save Excel spreadsheets, Word documents, and PowerPoint slides as Web pages.

Many companies use the Office suite to place information on their intranet because most employees are comfortable in Word and Excel. These tools are quite adequate for creating static Web content that some call brochure ware. Although somewhat bloated, the pages are faithful reproductions of the original document — especially when viewed in Microsoft’s latest Internet Explorer browser.

There’s nothing to stop you from using a “saved-as HTML” page in an ASP.NET site. However, you may find that removing the unwanted HTML markup takes more time than building the page from scratch.

Expression Web

Expression Web took over from Microsoft FrontPage as the content editor for professional designers. Although some see Expression as an advanced word processor for HTML pages, it’s actually much more, thanks to many important tools for Web designers. These tools include file management, link checking, style editing, and drag-and-drop support for HTML and ASP.NET controls.

Expression Web inherited the excellent split-view editor from FrontPage that lets you work in graphical and source code modes at the same time. The feature is so well done that Microsoft yanked the HTML editor from Visual Web Developer and substituted the superior Expression/FrontPage version.

Expression Blend

Expression Blend is mainly for the ponytail set (artistic types who prefer Macs) to create vector-based, animated, and three-dimensional graphics — much the way they do in Photoshop. Blend has a rich set of brushes, palettes, paint buckets, text, gradients, timelines, and event triggers for those with the skill to take advantage of them.

The XML-based files that Blend generates work in Windows Presentation Foundation (WPF) applications that run on Windows and in cross-platform Silverlight apps for the Web. (For more on Silverlight, see the section later in this chapter.

Blend’s user interface (UI) is dim and funereal — a far cry from the cheerful Windows XP or glitzy Windows Vista UI. The theory is that a drab, flat design environment doesn’t distract an artiste from his or her canvas.

Visual Web Developer (Including Express)

Visual Web Developer (VWD) is the premier tool for programming Web sites on the Microsoft platform. Just as Word is part of the Office suite, VWD is part of the bigger Visual Studio 2008 suite. Visual Studio includes Visual Basic .NET, Visual C#, and many other tools. Visual Studio comes in several versions to target teams of developers, database designers, testers, and system architects.

As an integrated development environment (IDE), Visual Web Developer helps you assemble and build the key elements of a Web application, including Web pages, images, controls, databases, style sheets, and, of course, the programming logic.

Visual Web Developer Express (VWDE), shown in Figure 1-1, is a somewhat stripped-down, freebie version intended for beginners and hobbyists. VWDE doesn’t support add-ons, source control, extensibility, or macros — features that professional developers expect in a tool.

Most of this book’s instructions are common to VWDE and VWD. You can do almost everything in this book with the free Express product. I note the few places in the book (mostly when debugging) that apply only to the upscale ($$$) version of product. Chapter 3 gives you the cook’s tour of VWD.

Figure 1-1: Visual Web Developer Express 2008.

Meeting the Technologies behind Web Applications

The technologies that support Web applications come from different organizations and from different teams within Microsoft. Here’s an overview of the parts that plug into — or on top of — each other.

Microsoft’s .NET 3.5 Framework

The .NET Framework is the base of what geeks call the stack.

You can think of the stack as a multilayered wedding cake where layers depend on the layer below for support. The .NET Framework (technically, a compiled portion called the Common Language Runtime, or CLR) sits at the bottom, and its code talks to the underlying operating system, such as Windows Server 2008 and Windows Vista. ASP.NET 3.5 depends on the .NET 3.5 Framework. (See the next section for more on this framework.)

You hear geeks refer to classes or class libraries that make up the .NET Framework. They use dot-filled names like System.Web, System.Data, and System.Xml.Linq. This dotty stuff is just a way to organize and categorize thousands of chunks of prewritten code that programmers can tap into via programming languages, such as C#, C++, and Visual Basic.

Microsoft provides tons of reference documentation on everything that’s in the .NET Framework. If you still don’t find what you need, you can peek into its source code to see how Microsoft makes it all work.

ASP.NET 3.5

ASP.NET 3.5 is a technology to deliver interactive, data-driven Web applications over the Internet and intranets. ASP.NET includes a large number of prebuilt controls, such as text boxes, buttons, images, and data grids, that you can assemble, configure, and manipulate with code to create HTML pages that correctly appear in all popular browsers.

When combined with programming logic, ASP.NET lets you send HTML code that’s specific to each user’s circumstances or requests. For example, if a user wants a Web page to show HTML tables with green text and a purple background, your code can read the incoming request, verify that it’s doable, and respond. This ability to create personalized, custom pages is known in the business as creating content on the fly and is a hallmark of server-side Web applications. Given that most people don’t want green text on a purple background, the “special-orders-don’t-upset-us” flexibility becomes a real bonus.

Unlike static HTML pages that are stored on disk in a fully complete state, ASP.NET pages usually exist in a skeleton-like state on disk. It’s only when a user requests a page that ASP.NET analyzes the markup, fills in all the content (often from a database), and sends HTML that the browser can render.

That’s a very quick summary of what ASP.NET does. Don’t fret if you don’t grasp it all yet. You can fill in the blanks as you jump around the rest of the book.

ASP.NET could have been XSP.NET

Instead of ASP.NET, the technology nearly became XSP.NET. In an interview with the Microsoft Architect Journal, Scott Guthrie, who helped establish Microsoft’s core Web technologies, recalls the naming issue.

“We originally called it XSP; and people would always ask what the X stood for. At the time it really didn’t stand for anything. XML started with that; XSLT started with that. Everything cool seemed to start with an X, so that’s what we originally named it.”

At another point, the technology was ASP+. That’s before Microsoft’s marketing department added a .NET suffix to almost everything that came out of Redmond.

Before the development of ASP.NET many of us learned to build sites with Active Server Pages, Microsoft’s first Web scripting platform. ASP (now called ASP Classic) got its name during Microsoft’s “Active” phase as in ActiveX, Active Desktop, and Active Directory.

ASP.NET Futures

The ASP.NET Futures releases consist of controls and technologies that the ASP.NET team is tinkering with or would like to demonstrate. It’s a way of getting feedback, testing scenarios, and pushing the envelope without making a commitment to release the product.

The Futures items have no official support, even though some work quite well. Some components, such as the dynamic data controls, get their start in ASP.NET’s Futures farm team and end up as professionals in an ASP.NET release or extensions update.

ASP.NET 3.5 Extensions

The ASP.NET team continues adding controls between official releases. These are packaged as extensions that you can download and install. As of this writing, the ASP.NET 3.5 Extensions include the Silverlight and MediaPlayer controls for presenting rich media on ASP.NET pages. Other recent extensions and templates include Dynamic Data controls for displaying database content and an advanced architectural framework called Model View Controller (MVC).

Microsoft has many terms for unfinished software such as alpha, beta, preview, community technical preview (CTP), and release candidate. For critical production use, check whether an ASP.NET extension has made it to the Released to Web (RTW) or Released to Manufacturing (RTM) stage.

Web services

Web services let you deliver data and calculations to remote computers without restricting your client base to those running Windows. The most popular exchange format is the Simple Object Access Protocol (SOAP), which lets different platforms talk to each other by using XML.

Microsoft put a big push into Web services via ASP.NET in previous .NET releases. The follow-on emphasis has been on services using Windows Communication Foundation (WCF). WCF services are more robust and easier to secure, especially for enterprise applications where you may be sharing healthcare data with a company that handles the billing.

Smaller Web sites also have some interesting uses for services, especially when hooked in with technologies such as ASP.NET AJAX. See Chapters 9 and 15 for examples of Web services.

JavaScript and client-side code

Modern browsers understand an internal programming language called JavaScript. When the browser encounters JavaScript code (script in geekspeak) inside an HTML page, it runs the program’s instructions. The browser (the client) doesn’t need a connection to the server to run JavaScript code — it’s completely independent. Client-side script uses the processing power of the computer on which the browser is running. That’s a tremendous advantage because it takes the pressure off the Web server and distributes tasks to individuals.

Client-side scripting becomes complicated — and extremely powerful — when combined with logic on the server. Imagine this scenario: The Web server sends a stream of HTML that contains JavaScript instructions. Those instructions include JavaScript code that checks whether the anonymous user has typed a number from 1 to 10 in a text box. The browser sees the script and executes it locally. Until the user has typed a number from 1 to 10, the Web server isn’t involved. When the browser sends the number back to the Web server, the return action is known as a postback. (See the sidebar “Postbacks and the rural mail carrier.”)

The powerful part is that the logic on the server can determine that 20 is an acceptable maximum number for a different customer and send a 20 in the JavaScript rather than the value 10. This way, the server is creating customized, client-side JavaScript on the fly.

Postbacks and the rural mail carrier

What better way to explain the concept of a Web page postback than by bringing in a mail carrier from Rural Route #2, Powassan? Say that I’m sending a snail-mail letter to my publisher. I address the envelope, affix a stamp, and carry the letter to Alsace Road and Ruth Haven Drive where the rural mailboxes are lined up. In this scenario, consider me the Web browser (that is, a client).

Along comes Sheila (the mail carrier) on her daily run. I hand Sheila the letter, which she takes to the postal station in Powassan. For this discussion, consider the postal station (and the postal workers in the building) as the Web server. In browser terms, I’ve just done a postback by sending in the letter for processing.

But wait a minute! A worker in the post office checks the stamp and sees that the postage is insufficient to send a letter to the United States. She sticks a label over the letter describing the problem and puts the letter back in the RR #2 bin to return to the sender. The next day, Sheila brings back my letter. I read the error message on the label, grumble, add more postage, and put the letter in the mailbox again. Sheila eventually takes the letter to the post office (the Web server) to resume its delayed journey.

My postback wasted time and resources because of the incorrect postage. Here’s a preferable scenario that avoids a useless postback:

When I hand Sheila the letter, she glances at the address and checks the stamp.

“Sorry, Ken,” she says. “You need 93 cents to send this!” and she hands the letter right back. (Remember, I’m the Web browser trying to submit something to the post office/server). I add the postage on the spot, and Sheila confirms the amount, accepting it without delay. This time, the postage was validated “on the client” without an unnecessary round trip.

When you hear about client-side validation, think of Sheila on RR #2, Powassan!

ASP.NET AJAX

Asynchronous JavaScript and XML (AJAX) is a technology that reduces unnecessary and wasteful full page refreshes by limited the transfer of data to and from the Web server. (See the sidebar “Demolishing the house to change a window.”)

On an AJAX-enabled page, you can type your credit card number in a text box, click the Submit button, and get a response such as “Credit Card Accepted” without disrupting the images, menus, and text elsewhere on the page. The browser sends only the required data to the server. When the message comes back, AJAX uses JavaScript code and Dynamic HTML to write into the designated part of the page.

Microsoft’s flavor of AJAX is an integral part of ASP.NET 3.5 rather than an add-on as in previous releases. As a result, if a bug or security flaw exists, Microsoft can fix its AJAX code via Automatic Updates or during the monthly celebration known as “Patch Tuesday.”

You see AJAX in action throughout this book, but specifically in Chapters 4 and 15.

Demolishing the house to change a window

To understand the benefits of AJAX, consider a renovation scenario. You’ve decided you want a stained glass window beside the front door. The renovator removes the existing plain glass and window frame, takes it to the shop for replacement with the stained glass, and returns to reinstall it. He obviously has no need to touch the other windows or — to be completely ridiculous — tear down the house and replace everything in the process.

The same concept applies to a Web page. If you just want to change the content in one area of the page, you don’t need to wipe out the existing page and ask the server to resend all the images and HTML markup. AJAX works like the renovator, doing just what’s required but not more.

Dynamic HTML

While not exclusively a Microsoft technology, Dynamic HTML (DHTML) plays an important role in making Web pages responsive, interactive, and more like a regular Windows program.

When the browser analyzes the HTML code for a page, it creates an in-memory document. This document has a hierarchical structure where child elements nest inside their parent containers. For example, table rows are nested inside tables that are nested within the document’s body.

The word dynamic in DHTML refers to the ability to change the characteristics of an element by using JavaScript. You’ve seen this ability many times without necessarily paying attention. For example, you’re seeing DHTML at work when you hover the mouse over an image, and the image changes. Likewise, DHTML is at work when you click a plus sign to expand a paragraph of text. Chances are, JavaScript is instructing the text (or its container) to become visible — even though the original code sent from the server set the text as hidden.

The ability of JavaScript and ASP.NET AJAX to manipulate and rewrite almost any part of a Web page (the text included) is what makes most dynamic effects possible.

Extensible Markup Language (XML)

Although Microsoft had a hand in the specifications for Extensible Markup Language (XML), the standards come from the World Wide Web Consortium (W3C). Microsoft uses XML extensively in its Web technologies as a way of passing data around. These data exchanges include browser-to-server, server-to-browser, server-to-server, and from one program to another. You see XML in Chapter 7 as part of LINQ to XML and again in Chapter 9 within Web services. XML is also a big part of AJAX.

XML data has three big advantages:

It’s generated as plain text so that it passes easily through firewalls.

Humans can read it and make at least some sense of it.

You can create, parse, and manipulate XML on any platform, not just on Microsoft’s operating systems.

Silverlight

Silverlight is Microsoft’s cross-browser, cross-platform multimedia plug-in. It works on Windows, Macs, and even the rival Linux platform.

You’ve almost certainly seen Macromedia (now Adobe) Flash movies on a Web page. Silverlight is like Flash, only faster, more technologically advanced, and easier to program, especially in .NET languages. This so-called Flash killer uses a form of XML markup called XAML (sounds like zamel and rhymes with camel) to generate its graphics and behaviors.

You can use Silverlight, shown in Figure 1-2, to embed everything from screencams to animated cartoons to full-motion video using live, streaming broadcasts. The download size is reasonable, and Silverlight runs in its own isolated area, known as a sandbox, so the program should be secure enough for most uses.

Figure 1-2: Silverlight video may become more common than Flash.

Silverlight is very appealing as a multimedia platform. It promises to be a very big deal as the tools and technologies become more advanced. Expect to see entire database-driven applications running on Silverlight that maintain their appearance even when you resize the browser. You can dip into Silverlight and other rich media types in Chapter 16.

Language Integrated Queries (LINQ)

Language Integrated Query (LINQ) is a set of additions to the C# and VB.NET programming languages that make it easier to deal with data. LINQ comes in several dialects, including LINQ to SQL, LINQ to XML, and LINQ to objects. After you master LINQ’s statements and syntax, you can apply the knowledge to all sorts of data. In fact, LINQ lets you combine data from multiple sources, such as a database, Web service, and XML file.

For most people, the big payoff is LINQ’s support for SQL Server. Instead of writing complicated SQL statements — and crossing your fingers that no syntax errors occur — LINQ lets you use familiar keywords in queries. Visual Web Developer (as with other members of the Visual Studio 2008 family) watches what you type and alerts you to problems.

Chapter 7 shows how to use LINQ to select, sort, and group data of all kinds. Chapter 8 focuses on the LinqDataSource control and DataContext object in ASP.NET applications and shows how to massage SQL Server data by using LINQ to SQL.

ADO.NET

ADO.NET is Microsoft’s technology for working with data and databases of all types. When a Web application talks to a database such as Microsoft SQL Server, it’s probably using ADO.NET. The introduction of LINQ has hidden much of ADO.NET from view in Visual Web Developer.

SQL Server

SQL Server 2005 and 2008 are key products in Microsoft’s Web technology strategy. The phrase “It’s all about the data” applies to most serious Web applications. Whether you’re tracking user preferences, generating complex reports, or storing customer orders, you need a fast and reliable data engine and relational database.

Microsoft provides SQL Server Express for free (but, as they say, “connect charges may apply”), making it a great choice for beginners. The skills and data you acquire by using SQL Express are directly transferable to the latest versions of SQL Server from standard to enterprise. You use SQL Server (mostly the Express version) throughout the book.

Internet Information Services

Internet Information Services (IIS) is Microsoft’s premier Web server product that comes free with the latest versions of Windows.

As a platform, IIS delivers Web pages and Web services as requested by a browser or other application. ASP.NET 3.5 meshes seamlessly with IIS to produce the dynamic pages you’re reading about in this chapter.

You can run IIS on your developer workstation, over your company’s intranet, or expose it to the vast public on the Internet. However, unless you’re running a large business on the Internet, you probably use IIS through an independent hosting company. These hosters are specialists who rent space on their servers, sell bandwidth, maintain connections to the Internet, and schedule backups.

During the development stage in Visual Web Developer, you may not use IIS at all. VWD includes a light Web server that does almost everything you need on your local development machine. When you’re satisfied with the pages and code, you transfer the site to an IIS machine from within VWD. (For details on deployment, see Chapter 20.)

Chapter 2

Getting Up and Running

In This Chapter

Installing Visual Web Developer Express

Setting up the development environment

Managing the Toolbox

Using Solution Explorer and the Properties window

Technically, you don’t need Visual Web Developer Express to create Web pages for ASP.NET. All the source and configuration files are text-based combinations of HTML, XML, and computer code. You could just fire up Notepad and start typing, although, it would take days to create anything worthwhile.

In reality, you need an integrated development environment (IDE) to automate the creation of files, generate the code, organize the content, and keep all the tools in one place.

This chapter brings you up to speed on Visual Web Developer Express as the design environment for ASP.NET pages. This chapter doesn’t cover everything the IDE can accomplish for you because you’re itching to build pages. When you understand the basics, you can get a grip on the rest of tools in subsequent chapters.

Installing Visual Web Developer Express

This section takes you through the installation of Visual Web Developer 2008 Express Edition (VWDE). If you’re using the full Visual Web Developer product that’s part of Visual Studio 2008, your setup is somewhat more involved because you have more choices. Apart from the installation, everything in this book about the Express edition applies to the paid version of Visual Web Developer. I flag instances where a feature’s available in the paid version but not in VWDE.

If you’ve installed prelease versions of VWDE, Visual Studio 2008/Orcas, SQL Server, SQL Server Express, or the .NET Framework 3.5, I recommend you uninstall them to start with as clean a system as possible. Always use the Windows uninstall utility to remove software. In XP, choose Control Panel⇒Add or Remove Programs; in Vista, choose Control Panel⇒Programs and Features.

You can download a free copy of Visual Web Developer 2008 Express Edition from Microsoft’s Web site. The full installation described in this section requires 3.5GB on the C: drive and a total download of 447MB.

If part of the installation fails, return to the Web site shown in the first step and begin the process again. The installer should pick up where it left off.

Follow these instructions to download and install VWDE:

1.In Internet Explorer, browse to http://www.microsoft.com/express/download/.

2.In the Web Install area of the page, locate the Visual Web Developer 2008 Express Edition product section, as shown in Figure 2-1.

Figure 2-1: Locating the Express edition download on Microsoft’s site.

3.Click the Download link.

A warning prompt appears, as shown in Figure 2-2.

Figure 2-2: A security warning about downloaded files.

4.Click Run.

The download of an initial 2.6 megabyte file starts.

5.If you’re using Windows Vista, click Continue on the User Account Control (UAC) warning, as shown in Figure 2-3.

Figure 2-3: A pesky UAC warning courtesy of Windows Vista.

6.On the Welcome to Setup screen (shown in Figure 2-4), click Next.

Sending anonymous setup information helps Microsoft analyze trends and catch oddball installation problems.

Figure 2-4: It’s safe to send anonymous setup information to Microsoft.

7.On the License Terms screen (shown in Figure 2-5), read every word of the license, consult your lawyer, select the radio button to acknowledge that you’ve read the terms (only if you read them!), and then click Next.

Figure 2-5: Study the license terms thoroughly because there might be a quiz.

8.On the Installation Options screen (see Figure 2-6), select all the optional products.

You can leave out the MSDN Express Library to save time and bandwidth.

Figure 2-6: It’s best to accept at least the SQL Server Express and Silverlight options.

9.On the Destination Folder screen (shown in Figure 2-7), you can accept the default install folder (unless you have reason to change it) and then click Install.

Coffee break time! The full download and installation can take over an hour even with a fast Internet connection.

Figure 2-7: The appearance of the Install button signals coffee break time.

10.When the Setup Complete screen finally appears (see Figure 2-8), click Exit and, when prompted, click Restart Now to reboot the computer.

You have 30 days before VWDE nags you into registering the product.

Figure 2-8: After completing the installation you need to reboot the computer.

Finally! Creating an ASP.NET Web Page

At this point, you have the software installed and you’re ready to take it for a spin. In this section, you create a trivial page so you can explore the environment. If you’re impatient to take on a larger project, jump to Chapter 3 and then return to “Tweaking Your Development Environment” later in this chapter for some configuration tips.

Starting the IDE

Similar to most installers, VWDE adds links to the Windows menu. To run the integrated development environment (IDE), click the Visual Web Developer 2008 Express Edition link from the main menu. The splash screen appears and the IDE comes alive. This can take a few moments (especially the first time) because there are background files to create and settings to write.

Okay! You’re viewing the default environment so prepare to make something happen!

Creating an ASP.NET Web site

Although you can edit a single Web page in VWD, you usually work on pages as part of a site. To create an ASP.NET Web site, follow these steps:

1.Choose File⇒New Web Site.

The New Web Site dialog box appears.

2.In the Templates section, near the top, select the ASP.NET Web Site template, as shown in Figure 2-9.

Figure 2-9: Selecting the ASP.NET Web Site template.

3.Ensure that File System is selected in the Location drop-down list.

4.Make sure Visual Basic is selected in the Language drop-down list.

5.Click OK.

The IDE goes to work and creates the Web site, a starter Web page, and some other files.

As shown in Figure 2-10, the IDE has three significant areas:

The Toolbox and other tabs scrunched along the border on the left and easy to miss. The Toolbox glides into view when you pass the mouse over its tab. Try it!

The default.aspx page opens in the Web page editor (the center).

Groups of small windows on the right, including one titled Solution Explorer.

The Web page editor offers three views:

Design view: Gives you a graphical page view that somewhat resembles what users see in the browser

Source view: Shows you the source code for the page, including the HTML markup.

Split view: Shows the graphical page view in one pane and the source code in another. When you make changes in one view, it prompts you to refresh the view.

Figure 2-10: The Toolbox tab, editing area, and windows in the VWDE IDE.

Adding an ASP.NET control

You can spice up the sad blank Web page by adding a control to it. A control is an object on a page that renders code or markup that a browser understands. Controls such as text labels, drop-down lists, grids, and text boxes are the objects that make Web pages interesting, dynamic, and useful.

To add a control to your Web page in Design view, follow these steps:

1.In the lower area of the page editor, click the Design button.

2.In the upper area of the editor pane, locate the default faint blue or gray box with dotted lines.

3.Put your mouse cursor into the inner rectangular area.

The area (a visual representation of an HTML <div> tag) becomes more prominent and displays a tab.

4.From the Standard section of the Toolbox, drag a Button control and drop it inside the rectangle that you located in the previous step. (If the Toolbox isn’t showing, make it visible by choosing View⇒Toolbox.)

Figure 2-11 shows the Button control in Design view.

Figure 2-11: The Button control in Design view.

Admittedly, this ASP.NET page is skimpy, but it’s enough for this preliminary exploration of the IDE.

Previewing a page in the browser

You can browse a page even while it’s under construction if you’re inside Visual Web Developer. The environment provides a Web server to compile the ASP.NET source code and render the HTML. It also launches the browser for you. To browse to a page within the IDE, follow these steps:

1.Place the mouse inside the ASP.NET page that you’re editing.

2.Right-click and from the context menu, choose View in Browser.

If you haven’t saved your work, the IDE prompts you to do so. If prompted, click Yes.

Internet Explorer opens and displays your page. You might need to deal with some nuisance security alerts from the browser by clicking to enable intranet settings.

3.For additional excitement, click the button on the page.

Other than a minor page flash, nothing much happens.

4.Close the browser.

You can save, build, and browse by pressing Ctrl+F5.

Tweaking Your Development Environment

In the preceding section, you used the development environment with its default settings. Microsoft’s choices aren’t always the best, so the first thing you want to do is configure the IDE for ease of use.

Showing all settings

For some reason, the people who created the IDE shield us from many customization features. To make sure all the settings are available, follow these steps:

1.In Visual Web Developer Express, choose Tools⇒Options.

2.In the bottom left corner of the Options window, check Show All Settings box.

Presto! You go from a few measly settings to more options than you can change in a day!

Unhiding advanced members

Even though you’ve expanded your options dramatically by showing all settings, Microsoft is still holding back. When you’re working with automatic statement completion (IntelliSense), the default settings hide many statements. To unhide the advanced members, follow these steps:

1.Open the Options window (Tools⇒Options).

2.Expand the Text Editor node and select All Languages.

3.In the Statement Completion area, clear Hide Advanced Members box.