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

Beginning Object-Oriented ASP.NET 2.0 with VB.NET From Novice to Professional

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

www.GetPedia.com

Click on your interest section for more information :

Acne

Fitness Equipment

Political

Advertising

Forums

Positive Attitude Tips

Aerobics & Cardio

Game

Pay-Per-Click Advertising

Affiliate Revenue

Goal Setting

Public Relations

Alternative Medicine

Golf

Pregnancy

Attraction

Dealing with Grief & Loss

Presentation

Online Auction

Hair Loss

Psychology

Streaming Audio & Online Music

Finding Happiness

Public Speaking

Aviation & Flying

Computer Hardware

Real Estate

Babies & Toddler

Holiday

Recipes & Food and Drink

Beauty

Home Improvement

Relationship

Blogging, RSS & Feeds

Home Security

Religion

Book Marketing

Humanities

Sales

Book Reviews

Humor & Entertainment

Sales Management

Branding

Innovation

Sales Telemarketing

Breast Cancer

Inspirational

Sales Training

Broadband Internet

Insurance

Satellite TV

Muscle Building & Bodybuilding

Interior Design & Decorating

Science Articles

Careers, Jobs & Employment

Internet Marketing

Internet Security

Casino & Gambling

Investing

Search Engine Optimization

Coaching

Landscaping & Gardening

(SEO)

Coffee

Language

Sexuality

College & University

Leadership

Web Site Promotion

Cooking Tips

Leases & Leasing

Small Business

Copywriting

Loan

Software

Crafts & Hobbies

Mesothelioma & Asbestos

Spam Blocking

Creativity

Cancer

Spirituality

Credit

Business Management

Stocks & Mutual Fund

Cruising & Sailing

Marketing

Strategic Planning

Currency Trading

Marriage & Wedding

Stress Management

Customer Service

Martial Arts

Structured Settlements

Data Recovery & Computer

Medicine

Success

Backup

Meditation

Nutritional Supplements

Dating

Mobile & Cell Phone

Tax

Debt Consolidation

Mortgage Refinance

Team Building

Debt Relief

Motivation

Time Management

Depression

Motorcycle

Top Quick Tips

Diabetes

Music & MP3

Traffic Building

Divorce

Negotiation

Vacation Rental

Domain Name

Network Marketing

Video Conferencing

E-Book

Networking

Video Streaming

E-commerce

Nutrition

VOIP

Elder Care

Get Organized - Organization

Wealth Building

Email Marketing

Outdoors

Web Design

Entrepreneur

Parenting

Web Development

Ethics

Personal Finance

Web Hosting

Exercise & Fitness

Personal Technology

Weight Loss

Ezine Marketing

Pet

Wine & Spirits

Ezine Publishing

Philosophy

Writing

Fashion & Style

Photography

Article Writing

Fishing

Poetry

Yoga

Beginning Object-Oriented ASP.NET 2.0 with VB.NET

From Novice to

Professional

Brian R. Myers

Beginning Object-Oriented ASP.NET 2.0 with VB.NET: From Novice to Professional

Copyright © 2005 by Brian R. Myers

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN (pbk): 1-59059-538-6

Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1

Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Lead Editor: Jonathan Hassell

Technical Reviewers: Ron Landers, Martin W.P. Reid

Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser

Associate Publisher: Grace Wong

Project Manager: Kylie Johnston Copy Edit Manager: Nicole LeClerc Copy Editor: Julie M. Smith

Assistant Production Director: Kari Brooks-Copony Production Editor: Ellie Fountain

Compositor: Linda Weidemann, Wolf Creek Press

Proofreaders: Elizabeth Berry and Linda Seifert Indexer: Carol Burbo

Artist: Kinetic Publishing Services, LLC Interior Designer: Van Winkle Design Group Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski

Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com.

For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.

The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

This book is dedicated to my dad, Donald Myers Jr., who helped me understand the value of work and who thought I should “do something

in computers.” I am very glad I took that advice.

In Loving Memory of Donald Myers Jr. February 18, 1945–April 23, 1998

Contents at a Glance

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

CHAPTER 1 An Introduction to .NET and Visual Studio 2005 . . . . . . . . . . . . . . . . . . 1

CHAPTER 2 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

CHAPTER 3 Attributes and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

CHAPTER 4 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

CHAPTER 5 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

CHAPTER 6 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

CHAPTER 7 Class Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

CHAPTER 8 ASP.NET Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

CHAPTER 9 ASP.NET Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

CHAPTER 10 Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

v

Contents

About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

CHAPTER 1 An Introduction to .NET and Visual Studio 2005 . . . . . . . . . . .

1

VB.NET and ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

An Introduction to Microsoft .NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

The Common Language Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Assemblies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

An Introduction to Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

How to Get Started with Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . 4

Creating a New Web Project (ASP.NET) . . . . . . . . . . . . . . . . . . . . . . . . . 6

Opening an Existing Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Building Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Accessing a Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Navigating the Visual Studio Environment . . . . . . . . . . . . . . . . . . . . . 21

Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

IntelliSense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

CHAPTER 2 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

27

Introduction to OOP Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Why Objects Exist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Objects As the Building Blocks of OOP . . . . . . . . . . . . . . . . . . . . . . . . 29

Introduction to Reusability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

vii

viii C O N T E N T S

Introduction to OOP with .NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

Objects in .NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Using the Object Browser in Visual Studio 2005 . . . . . . . . . . . . . . . . 34

Creating a Class with VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

Using a Class in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

CHAPTER 3 Attributes and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Attributes and Actions Within VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

VB.NET Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Adding Properties to a VB.NET Class . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Using a Class Public Property in VB.NET . . . . . . . . . . . . . . . . . . . . . . . 45

VB.NET Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Parameters in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Adding Methods in VB.NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

Using a Method in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

CHAPTER 4 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

57

A General Overview of Encapsulation and Information Hiding . . . . . . . . . 57

Encapsulation in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Information Hiding Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Encapsulation Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

CHAPTER 5 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

71

Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Inheritance in VB.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84