Build Your Own ASP.NET Website Using C# & VB.NET. Pt. 1.
Build Your Own ASP.NET Website Using C# & VB.NET. Pt. 1.
Reproduced from "Build Your Own ASP.NET Website Using C# & VB.NET" by permission of SitePoint. ISBN 0-9579218-6-1 , copyright 2004. All rights reserved. See http://www.sitepoint.com/ for more information.
Notice of Rights
All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.
Notice of Liability
The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.
Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.
List of Figures
- 1.1. The Web server is responsible for processing the server-side code and presenting the output to the user (client).
- 1.2. If the .aspx ISAPI Extension DLL appears within the Application Mappings menu, then ASP.NET was installed correctly.
- 1.3. Select the Stop icon to stop IIS.
- 1.4. Once the virtual directory has been created, it will appear within the list of sites.
- 1.5. Enabling directory browsing for the Web server provides you with the ability to view directories in a way that’s similar to the view you’d see within Windows Explorer.
- 1.6. Install MSDE by running the command line executable and setting necessary parameters.
- 1.7. MSDE runs out of sight within the task bar tray.
- 1.8. Web Data Administrator allows you to work with your databases within MSDE.
- 1.9. We’ll create a simple ASP.NET page that says "Hello there" and displays the time.
- 2.1. All the elements of an ASP.NET page are highlighted. Everything else is literal text and HTML tags.
- 2.2. ASP.NET supports view state. When a page is submitted, the information within the controls is preserved.
- 3.1. The Page_Load event is raised, the subroutine is called, and the code within the subroutine is executed.
- 3.2. The Page_Load event is raised, the function is called, and the code within the function is executed.
- 3.3. The methods defined by the class interact with the object.
- 3.4. A class serves as the blueprint for an object.
- 4.1. Create the interface of the ASP.NET page using HTML controls.
- 4.2. A Web Form contains code for processing logic and Web controls for presentational purposes.
- 4.3. The HyperLink control renders similar to the anchor tag in the browser.
- 4.4. Append the selected item to the query string.
- 4.5. Set the text property of the label control within a Page_Load event handler to accept the new parameter value.
- 4.6. The IsPostBack property checks to make sure the user isn’t resubmitting the page.
- 4.7. Add HyperLink controls for the Intranet navigation menu.
- 4.8. Open Notepad and save the file as styles.css within the root directory of the application folder.
Table of Contents
- Who Should Read This Book?
- What’s Covered In This Book?
- The Book’s Website
- The Code Archive
- Updates and Errata
- The SitePoint Forums
- The SitePoint Newsletters
- Your Feedback
Here I am, seven years after the inception of ASP, still using a technology that I initially only glanced over as I searched for a server-side alternative to ColdFusion.
ASP and VBScript seemed like the best alternative. I’d taken basic programming classes in college, and I guess they helped, because these two technologies came easily to me. Shortly thereafter, I went back to school and got into Visual Basic, COM, DCOM, and more. A whole new world was opening up to me through simplicity offered by ASP.
Seven years, and countless Windows, Web, and wireless applications later, I still swear by the next generation of a technology that I’ve always considered superior to the major alternatives. ASP.NET represents a new and efficient way of creating Web applications using the programming language with which you feel most comfortable. Though it can take some time to learn, ASP.NET is simple to use. Whether you want to create Web Forms complete with Web and validation controls, or you aim to build a feature-rich shopping cart using DataTables, all the tools you’ll need to get up and running are immediately available, easy to install, and require very little initial configuration.
This book is aimed at beginner, intermediate, and advanced Web designers looking to make the leap into server-side programming with ASP.NET. You’ll be expected to feel comfortable with HTML, as very little explanation is provided here.
By the end of this book, you should have a firm grasp on what it takes to download and install ASP.NET and the .NET Framework, configure and start your Web server, create and work with basic ASP.NET pages, install and run either Access or MSDE, create database tables, work with advanced, dynamic ASP.NET pages that query, insert, update, and delete information within a database.
This book is comprised of the following seventeen chapters. Read them from beginning to end to gain a complete understanding of the subject, or skip around if you feel you need a refresher on a particular topic.
- Chapter 1: Introduction to .NET and ASP.NET
Before you can start building your database-driven Web presence, you must ensure you have the right tools for the job. In this first chapter, I’ll tell you how to find, download, and configure the .NET Framework. I’ll explain where the Web server is located and how to install and configure it. Next, we’ll walk through the installation of two Microsoft database solutions: Access and MSDE. Finally, we’ll create a simple ASP.NET page to make sure that everything’s running and properly configured.
- Chapter 2: ASP.NET Basics
In this chapter, you’ll create your first useful ASP.NET page. We’ll cover all of the parts that make up a typical ASP.NET page, including directives, controls, and code. We’ll then walk through the process of deployment, focusing specifically on allowing the user to view the processing of a simple ASP.NET page through the Web browser.
- Chapter 3: VB.NET and C# Programming Basics
In this chapter, we’ll look at two of the programming languages used to create ASP.NET pages: VB.NET and C#. You’ll learn about the syntax of the two languages as we explore the concepts of variables, data types, conditionals, loops, arrays, functions, and more. Finally, we’ll see how the two languages accommodate Object Oriented Programming principles by allowing you to work with classes, methods, properties, inheritance, and more.
- Chapter 4: Web Forms and Web Controls
ASP.NET is bundled with hundreds of controls that you can use within your applications, including HTML controls, Web controls, and more. This chapter will introduce you to the wonderful world of Web controls and how Microsoft basically reinvented HTML forms.
- Chapter 5: Validation Controls
This chapter introduces validation controls. With validation controls, Microsoft basically eliminated the heartache of fumbling through and configuring tired, reused client-side validation scripts.
- Chapter 6: Database Design and Development
Undoubtedly one of the most important chapters in the book, Chapter 6, Database Design and Development will help you prepare to work with databases in ASP.NET. We’ll cover the essentials you’ll need in order to create a database using either Access or MSDE. In this chapter, we’ll begin to build the database for our project.
- Chapter 7: Structured Query Language
This chapter introduces the language we’ll use to facilitate communications between the database and the Web application: Structured Query Language, or SQL. After a gentle introduction to the basic concepts of SQL, we’ll move on to more advanced topics such as expressions, conditions, and joins.
- Chapter 8: ADO.NET
The next logical step in database driven Web applications involves ADO.NET. This chapter explores the essentials of the technology, and will have you reading data in a database directly from your Web applications in just a few short steps. We’ll then help you begin the transition from working with static applications to database-driven ones.
- Chapter 9: The DataGrid and DataList Controls
Taking ADO.NET further, this chapter shows you how to utilize the DataGrid and DataList controls provided within the .NET Framework. DataGrid and DataList play a crucial role in the simplicity of presenting information with ASP.NET. In learning how to present database data within your applications in a cleaner and more legible format, you’ll gain an understanding of the concept of data binding at a much higher level.
- Chapter 10: DataSets
One of the most challenging concepts to grasp when transitioning from ASP to ASP.NET is that of disconnected data. In this chapter, you’ll learn how to use DataSets to create virtual database tables within your Web applications. You’ll also learn how to work with DataTables, and how to filter and sort information within DataSets and DataTables using DataViews.
- Chapter 11: Web Applications
Chapter 11, Web Applications explores the features of a Web application. We’ll discuss the many parts of the Web.config file in depth, and understand how to work with the Global.asax file, application state, and session state. Finally, we’ll look at the ways in which caching can improve the performance of your Web applications.
- Chapter 12: Building an ASP.NET Shopping Cart
In this chapter, we’ll create an ASP.NET shopping cart. Using the topics we’ve explored in previous chapters, including DataTables and session state, we’ll walk through the process of building a purely memory-resident shopping cart for our project.
- Chapter 13: Error Handling
Learning to handle gracefully unforeseen errors within your Web applications is the topic of this chapter. Initially, we’ll discuss basic page and code techniques you can use to handle errors. We’ll then talk about the debugger that’s included with the .NET Framework SDK and understand how to leverage it by setting breakpoints, reading the autos and locals window, and setting watches. Finally, we’ll discuss how you can take advantage of the Event Viewer to write errors as they occur within your applications.
- Chapter 14: Security and User Authentication
This chapter will introduce you to securing your Web applications with ASP.NET. Here, we’ll discuss the various security models available, including IIS, Forms, Windows, and Passport, and discusses the roles the Web.config and XML files can play.
- Chapter 15: Working with Files and Email
In this chapter, we’ll look at accessing your server’s file system, including drives, files, and the network. The chapter will then show you how to work with file streams to create text files, write to text files, and read from text files on your Web server. Finally, you’ll learn how to send emails using ASP.NET.
- Chapter 16: Rich Controls and User Controls
Chapter 16, Rich Controls and User Controls explores ASP.NET’s rich controls. You’ll learn how to create an interactive meeting scheduler using the Calendar control, sessions, and serialization. You’ll also learn how to format XML with XSLT utilizing the Xml control. Lastly, we’ll look at randomizing banner advertisements on your site using the AdRotator control.
- Chapter 17: XML Web Services
The newest buzzword in the development community is “Web Services,” and this chapter hopes to shed some light on the topic. We first define Web Services before moving on to explain how they’re used, where they can be found, and what WSDL and UDDI are. In this chapter, you’ll create a couple of different Web Services from scratch, including one that queries your database to present information within a Web application. You’ll also learn how to build a search application using the Google Search Web Service.
Created: March 27, 2003
Revised: June 18, 2004