Beginning Object-Oriented ASP.NET 2.0 with VB.NET From Novice to Professional
.pdf■C O N T E N T S ix
■CHAPTER 6 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
85 |
The Purpose of a Namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
.NET Framework Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Creating a Namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The My Namespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
■CHAPTER 7 Class Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
101 |
Class Design Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Business Process Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Define the Business Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Case Study: Define the Business Process . . . . . . . . . . . . . . . . . . . . . 103
Review the Business Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Break Down the Business Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Case Study: Break Down the Business Process . . . . . . . . . . . . . . . 106
Create the Class or Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Define the Properties and Methods of Each Class . . . . . . . . . . . . . . . . . . 112
Case Study: Define the Properties and Methods of Each Class . . . 113
Create the Class Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Case Study: Create the Class Structure . . . . . . . . . . . . . . . . . . . . . . 118
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
■CHAPTER 8 ASP.NET Web Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Using the Web Forms Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Adding Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
The ASP.NET Page Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Page Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Round Trips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Web Form Processing Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Session and Application Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Expanding the Help Desk Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
x ■C O N T E N T S
■CHAPTER 9 ASP.NET Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
HTML Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Web Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Working with Control Properties and Events . . . . . . . . . . . . . . . . . . . 152
Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Expanding the Help Desk Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
■CHAPTER 10 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Introduction to XML, SOAP, and WSDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Introduction to Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Creating a Web Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Consuming a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
ac20478e3412082af91ad516b5bf0c90
About the Author
■BRIAN MYERS is a software engineer and database administrator for a large manufacturing company. He is a Microsoft Certified Solution Developer for .NET, a Microsoft Certified Application Developer for
.NET, and a Microsoft Certified Professional. He holds an Associates Degree in Microcomputer Applications Development from the Pennsylvania College of Technology and a Bachelors of Information Systems from Pennsylvania State University. Along with his professional
accreditations, he is also an Eagle Scout.
He has been working with VB since VB 5 and has been writing OOP applications for over seven years. He has more than seven years of experience as a software developer, mostly with Microsoft technologies. Prior to taking his current position in June 2004, he worked for a consulting company for six years, handling various development projects as a developer as well as a project manager.
Brian has also written articles for www.AspToday.com as well as teaching courses in
.NET development and SQL Server.
xi
About the Technical Reviewer
■RONALD LANDERS is the President and Senior Technical Consultant for IT Professionals, Inc. (ITP), a staffing, recruiting, development, and IT project services company. Mr. Landers has over 20 years of experience in the IT field and specializes in database design and implementation, application design and architecture, and web-based technologies, such as web services, electronic commerce, and web portals.
In addition to ITP, Mr. Landers has been teaching IT classes for UCLA Extension for the past 13 years. Currently, Mr. Landers’s courses include beginning and advanced classes in SQL Server, ASP.NET, Web Services, and Object Oriented Programming.
xiii
Acknowledgments
First I would like to thank my wife, Catharine Miller, for her support while I wrote this book. Thank you for giving me the time to write this book as well as teach. Thank you for allowing me to do what I love and love what I do. A very big thank you goes to Amy Cook and Jennifer Bitting for reviewing my development drafts, and for giving me feedback. Without your initial feedback, the revision process would have taken much longer. Thank you to Jon Hassell, my editor, for helping me along with my first book. Thank you also to many others at Apress, such as Dominic Shakeshaft for giving me the opportunity to write this book, Kylie Johnston for helping the book along the process, Julie Smith for the copy editing, and Ellie Fountain for helping the book through production. Without the whole team at Apress I would not have been able to write this book.
This book, as well as my career, would not have been started without the help of the instructors at the Pennsylvania College of Technology. The instructors not only taught me software development, but also taught me the value of not just concentrating on technology. The most important of these instructors was not only my instructor but also my advisor, Mr. Al Henry. He helped me see that to be a well-rounded software developer, I also needed to take business courses to understand the business side of any organization. I used that advice to pursue my Bachelors of Information Systems degree from Penn State, which required 50% of its credits in IT-related courses and 50% of its credits in businessrelated courses. Without Mr. Henry’s urging, I probably wouldn’t have taken more business courses and I probably would not be where I am today in my professional career. I hope that is a lesson to other young software developers—to compete in the current environment, you must understand business.
Finally I want to thank the rest of my family—my mother Betty, my sister Michelle, and my brother Jim. I am very grateful for everything that you have done for me.
One last thing, to my niece Erica and nephew Ryan: See, this shows you can do anything you want to.
xv
Introduction
This book was born out of a lunch that I had with two colleagues of mine. They both had an extensive background in mainframe development, but they were struggling to understand what OOP was and how they should apply it. During the conversation, I explained some of the basics of OOP and afterwards thought about better ways to teach these developers the concepts of OOP. That lead me to decide that I should write a book, which lead me to Apress—and the rest is history.
Object-Oriented Programming is important in today’s ever-changing world. More and more businesses are abandoning mainframe development for client/server development. Client/server development is greatly enhanced by OOP techniques. OOP techniques teach developers to build reusable code and to think about a problem in terms of the real world. OOP is all about modeling the real world to make more userand business-friendly software applications.
In the past couple of years, Microsoft announced a new version of .NET that was to be delivered in 2005. Visual Basic 2005, Visual Studio 2005, and ASP.NET 2.0 all provide new functionality and great advantages. This book first teaches the concepts of OOP and then uses the newest version of .NET to develop ASP.NET web sites. Many companies are starting to develop most, if not all applications, as web applications. This book helps position the reader to develop web sites with the newest version of .NET and with OOP concepts.
If you have developed web sites with traditional ASP, you will learn how to develop web sites with VB.NET, which is a very big improvement over traditional VBScript and JavaScript.
Who This Book Is For
There are two main groups that this book was written for. The first is the group of procedural developers that have spent many years writing software for mainframes. The transition from procedural programming to OOP can be a difficult one. This book provides a path for that transition, by first explaining OOP concepts and then explaining how to implement those concepts with the latest technologies from Microsoft. This book also includes a chapter (Chapter 1) that introduces Visual Studio and the whole concept of .NET.
The second group this book was written for is the VB6 and traditional ASP developers. Microsoft is strongly encouraging developers to move to .NET. Whether you agree with that strategy or not, looking at the newest technology and learning how to use it
xvii
xviii ■I N T R O D U C T I O N
to develop new applications may help solve some very difficult problems. As a developer that first learned VB5, and then VB6, and then made the jump to VB.NET, I know it’s scary. You are comfortable with the syntax and the concepts. However, as a developer that has made the transition, I can tell you my development is much quicker now and I can deal with much more complex problems. There are several hurdles that you need to overcome, but this book is a very good first step. If you have not worked with OOP with VB6 or ASP, this book also introduces the concepts. If you have used OOP, then this book will help you transition from VB6 to VB 2005. If you have developed web sites with traditional ASP, then this book will help you find the advantages to ASP.NET and show you how to create web sites with the full VB.NET language, instead of the VBScript or JavaScript languages.
How this Book is Structured
•Chapter 1, “An Introduction to .NET and Visual Studio 2005”
This chapter provides an introduction to the Microsoft .NET strategy, including an introduction to each of the components, such as the common language runtime. This chapter also includes an introduction to Visual Studio 2005, the latest version of the Visual Studio development tools.
•Chapter 2, “Object-Oriented Programming”
This chapter provides an overview and introduction to Object-Oriented Programming. This chapter starts by explaining what an object is and why it is important. This chapter then briefly introduces the various Object-Oriented Programming concepts, which are covered in more depth in the remaining chapters.
•Chapter 3, “Attributes and Actions”
This chapter explains the concepts of attributes and actions within the context of Object-Oriented Programming. After providing an introduction and an ObjectOriented Programming background for each of these concepts, the chapter explains how to implement attributes and actions within VB.NET classes.