Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ASP.NET 2.0 Instant Results

.pdf
Скачиваний:
67
Добавлен:
17.08.2013
Размер:
11.03 Mб
Скачать

Introduction

For all of the programmers out there who just love a good .NET book to get them up and running fast in a new technology, you are in luck. ASP.NET 2.0 Instant Results is the perfect fast-track book for the programmer or architect to pick up on the new features and tools available in the 2.0 version of ASP.NET. Sure, you could read a traditional book, and spend countless hours guessing what you really have to do in order to get the software to work properly—or you could simply use the materials in the following chapters to understand and test the example projects provided in a short amount of time.

Some of the compelling reasons to produce this book are tied to the incredible reviews about the 2.0 version of the .NET Framework, along with the development advancements seen within the Visual Studio 2005 environment. ASP.NET 2.0 is a hot technology, poised for rapid adoption and growth compared to the 1.1 version, thanks to some exciting features that focus on providing web developers with the tools they need for the majority of their development projects. These must-haves include the new login controls, which enable developers to quickly drag and drop a set of controls on the design surface, set a few properties, and have a near-instantaneous security system. Another new feature is the enhancements to the design-time user interfaces for binding data controls. A wizard-like aspect surrounds most of the controls, which are in fact very easy to operate. Other exciting controls exist, but they are not the end of the story. A vast amount of changes has been planted within ASP.NET 2.0, involving the architecture of sites, speed of page requests, management of stateful information, and efficiency of development overall. Sound too good to be true? Well, if you are taking on ASP.NET 2.0, your programming effort just got a whole lot easier.

Who This Book Is For

This book is ideal for any programmer with .NET experience to learn the new technology. Anyone who has experimented with .NET 1.1 or implemented full-scale solutions for their employers would be a perfect candidate to easily absorb all of the materials within this book. You should have some general understanding of how a basic database works, with experience in developing software to access a database object such as a stored procedure.

For a beginner, you may want to skip over to Chapter 7. This chapter is very lightweight in design, aimed at providing a simplistic approach to a very common web site style. That is, the family photo album web site. This chapter explains the basic concepts of sharing photos within a web site and adding and deleting photos. It would be a great way to catch the basic concepts early on, before diving into more complicated site designs and concepts within the book.

The best approach for advanced readers is to find a chapter that interests you, and skip right to it. No ground is lost by moving through this reference book of geniuses (shameless plug). It is meant to be a helpful guide and a reference quick-start for diving deep into working code, in an attempt to learn it rapidly. Each chapter is almost completely self-contained and is a completely different implementation of various overlapping features. Some chapters may repeat a concept for a redundant and thorough learning process, whereas others may divert from the consistent features and usages in order to provide a broad approach to the site’s unique requirements. In some cases, where you require a full explanation of a topic that has previously been discussed, you’ll find a reference to an earlier chapter that describes that topic in great detail.

IntCuroductionrentHead

What This Book Covers

The book contains a dozen projects you can use right off the disk with minimal setup needed. Each project has step-by-step instructions on installing the source code to your local machine. The goal of the chapter and accompanying project code is to enable you to understand and quickly modify the project to enhance its capabilities or to learn how to implement some of the features it uses within different situations. Through the repeated studying of simple project walkthroughs and hands-on experimentation, you learn more about the design and creation of full projects in the 2.0 version of ASP.NET. The book references some of the advancements since the older version 1.1, but not to any level of detail. Most of the logic and material is gauged toward explaining the deeper concepts within the 2.0 version in its entirety.

How This Book Is Structured

This book is designed in similar fashion to other Wrox Press Instant Results titles, in that it serves as more of a reference manual of usable and instructional source projects, as compared to a traditional end- to-end book. This is because most programmers do not need to absorb all of the available information on a particular subject in a traditional fashion. Many times, programmers are looking to find the answers within the code, and then read content or material on it as an afterthought. This book aims to satisfy this tendency, but not at the expense of providing quality information and useful instruction at the same time. Thus, the topics and concepts that must be learned are taught from basic to advanced forms, across all of the 12 projects, with overlapping tools and features to drive home the concepts.

The structure of each chapter follows the following general pattern:

Overview—What does this project do?

Design

Code and code explanation

Setting up the project

Each project is designed with reusable controls, class files, and/or modules. Classes and noteworthy project files are highlighted and analyzed with sufficient information in each chapter to make the research effort as easy as possible.

The chapters of the book, and consequently the source projects used within the book, are as follows:

Chapter 1: The Online Diary and Organizer

Chapter 2: Wrox File Share

Chapter 3: Wrox Chat Server

Chapter 4: Wrox Survey Engine

Chapter 5: Wrox CMS

Chapter 6: Wrox Blog

Chapter 7: Wrox Photo Album

Chapter 8: Customer Support Site

xviii

CurrentIntroductionHead

Chapter 9: Wrox WebShop

Chapter 10: Appointment Booking System

Chapter 11: Greeting Cards

Chapter 12: The Bug Base

The easier chapters to pick up and learn might include Chapters 4, 7, and 9, whereas Chapters 3, 10, and 12 all provide advanced topics you will be sure to learn from.

At the end of your studies, you will be able to create your own site from scratch, implementing security, a structured architecture, profiles, new and more efficient data-bound controls, object-based data binding, and many more features.

What You Need to Use This Book

The basic software needed to use this book includes Windows 2000 Professional or Windows XP Professional and an installation of Visual Web Developer Express Edition with SQL Server 2005 Express Edition. Visual Web Developer Express Edition is available from http://msdn.microsoft.com/vstudio/ express/vwd/. As an alternative to Visual Web Developer Express Edition, you can use one of the full versions of Visual Studio 2005, including the Standard and Professional editions. It is understood with the development tools mentioned that the .NET Framework version 2.0 is required to run the project samples as well.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available on the companion CD-ROM and for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Search box or by using one of the title lists) and click the Download Code link on the book’s detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 0-471-74951-6 (changing to 978-0-471-74951-6 as the new industry-wide 13-digit ISBN numbering system is phased in by January 2007).

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another

xix

IntCuroductionrentHead

reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport

.shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1.Go to p2p.wrox.com and click the Register Now link.

2.Read the terms of use and click Agree.

3.Complete the required information to join as well as any optional information you wish to provide and click Submit.

4.You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You’ll find this book’s own forum under the Books category that is available from the homepage or by clicking View All Forums on the menu on the left. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

xx

1

The Online Diar y

and Organizer

By the end of this chapter you’ll have created an online diary, organizer, and contacts manager. So what exactly does the online diary and organizer do? Using a calendar-based interface it allows you to add, delete, and edit a diary entry for any day. It also allows you to create events: for example, to keep a note of your rich Uncle Bob’s birthday — wouldn’t want to forget that, would you? It’s not just limited to birthdays, but any event: meetings, appointments, and so on.

The system has a basic username and password logon system, so that only you and no one else can view your own diary. This is what differentiates it from a blog. This system is a private diary and contacts manager — a place to put all those thoughts and comments you’d rather not have the world see. Unlike a blog, where you want the world to see it!

This whole project demonstrates the power of ASP.NET 2.0 and how easy it makes creating projects like this. Gone are the days of hundreds of lines of code to do security logons, create new users, and so on. This chapter employs the new security components of ASP.NET 2.0 to show just how easy it is to create fun, exciting, and useful projects.

The first section takes you through using the diary and its main screens. Then, the “Design of the Online Diary” section walks you through an overview of the system’s design. After that you get into the nuts and bolts of the system and how it all hangs together. In the final section, you set up the diary.

Using the Online Diar y

Each user has his or her own online diary; to access it requires logging on. Enter username user5 with the password 123!abc to log in as a test user. The log on screen is shown in Figure 1-1.

Although the screenshot may suggest lots of controls and lots of code to make the security function, in fact with the new security controls in ASP.NET 2.0 it’s very easy and not much work at all.

If you have not registered, a link will take you to the Sign Up page, depicted in Figure 1-2.

Chapter 1

Figure 1-1

Figure 1-2

This shows another of the new security controls in ASP.NET 2.0; creating a registration process is now just a matter of adding a control to a form!

If you’ve forgotten your password, you can click the Forgotten Your Password? link, which directs you to the Password Reminder wizard pages (see Figure 1-3).

Figure 1-3

Having logged on, you arrive at the main diary page, as displayed in Figure 1-4.

2

The Online Diary and Organizer

Figure 1-4

On this page you see a monthly calendar. Days with diary entries are marked with a blue background. Days with events are marked in red text. Notice also on the right that upcoming events are highlighted, as are recent diary entries.

Clicking on a day moves you through to the area where you can enter your diary entry for that day; and add, edit, and delete events (see Figure 1-5).

Figure 1-5

3

Chapter 1

You can also navigate your diary from here via the small calendar to the right.

Adding a diary entry simply involves typing in the Entry Title and Diary Text boxes and clicking the Save Entry button.

Events happening on a particular day are listed in the Events table at the bottom-left of Figure 1-5. You can edit and delete events, or click the Add New Event link to add a new event. The Edit and Add event pages are almost identical in look. An example of the Edit Event page is shown in Figure 1-6.

Figure 1-6

In the Edit Event page, you can set the event’s name, include a brief description, what time the event starts, and how long it lasts.

Returning to the main diary page (refer to Figure 1-4) you’ll see a Manage Your Contacts link, as shown in Figure 1-7.

Figure 1-7

Clicking that link takes you to the Contact Management page (see Figure 1-8).

4

The Online Diary and Organizer

Figure 1-8

Here you see a list of your contacts, which you can edit and delete by clicking the appropriate link in the Contacts table. You can also add a new contact by clicking the Add New Contact link, which takes you to the New Contact page (no surprise there!), shown in Figure 1-9.

Figure 1-9

Currently the contacts functionality is fairly simple, with such things as linking events and contacts and automatically e-mailing contacts to remind them of an event.

5

Chapter 1

So you’ve seen what the Online Diary does, now you can look at how it does it! The next section describes the overall design and how the system hangs together. You get a high-level tour of the database setup and each of the classes the system uses.

Design of the Online Diar y

The diary system is split into the common three-layer architecture. All data and direct data modifying code are in the data layer, a combination of database tables and stored procedures. The data access layer is examined next.

Above the data access layer is the business layer providing all the rules and intelligence of the system. The business layer has been coded as seven classes, which you tour through shortly.

Finally, the bit the user sees is the presentation layer, consisting of a number of .aspx files that utilize the business and data access layers to create the diary’s interface. This layer is discussed in the last part of this section.

The Data Access Layer

The Online Diary uses a SQL Server 2005 Express database. However, there’s no reason why this couldn’t be changed to work with other databases. If the database supports stored procedures, then in theory all that’s needed is a change of connection string and creation of stored procedures matching those in the current SQL Server database. If the database doesn’t support stored procedures — for example, MS Access — changes to class code would be necessary but not difficult.

Figure 1-10 shows the tables in the Online Diary database (DiaryDB).

Figure 1-10

6