LANGUAGES: VB | C#
TECHNOLOGIES: Visual Studio .NET | ASP.NET Web Matrix | Notepad
Choose a Development Tool
Find the best way to develop applications.
By Wayne S. Freeze
Computers have come a long way since the days when programmers had to type their programs on punch cards and feed them to faceless mainframes for execution. Although the hardware has changed, the fundamental concepts remain the same: To write a program, you must punch away on a keyboard. Fortunately, the tools that have replaced the keypunch also have evolved. But as you'll see in this article, their evolution has taken them in several different directions.
A Trio of Development Tools
You can use many tools to develop ASP.NET applications, and Microsoft offers three. Visual Studio .NET is the premier development tool for ASP.NET programmers. It offers a comprehensive set of features designed to help a programmer create many different kinds of .NET programs. Its downside is that it can cost anywhere from $100 to more than $2,000, depending on the features you choose to purchase.
The ASP.NET Web Matrix Project is less sophisticated than Visual Studio .NET, but it comes with a nice assortment of features targeted at the ASP.NET developer. One of its nicest features is that it is available free of charge.
The simplest development tool is Notepad, which some developers jokingly refer to as Visual Notepad. Unlike Visual Studio .NET and Web Matrix, Notepad is a simple text editor. It has none of the bells and whistles you would find in Web Matrix or Visual Studio .NET, but Notepad also has none of their idiosyncrasies.
I refer to Notepad as a development tool, but it is merely one of several text editors available in Windows. DOS lovers still can use the Edit command to edit any text file. Notepad is the first graphical text editor available for Windows, but I prefer to use WordPad because it handles larger files better and it supports more file types. In fact, I usually copy the executable file associated with WordPad (Write.exe) over the Notepad.exe file to ensure I always use WordPad.
Notepad is a WYTIWYG (what you type is what you get) development tool; you must enter every piece of code yourself. It doesn't have any features to generate code automatically or help you design the HTML visually. Each Web page is stored in a separate file and shares nothing with any other Web pages unless you create the appropriate definitions to the common file explicitly and create the common file separately.
Each ASP.NET program you create with Notepad is simply a collection of HTML tags. All the code associated with the program is stored between the and tags. The code references various elements in the HTML section by using the name specified in the id attribute.
Likewise, you associate event handlers in your code by specifying the appropriate onXxx attribute in the HTML tag. By convention, the name of the subroutine for the event is constructed by using the id of the HTML element followed by an underscore (_) and the name of the event. You aren't bound to this format; you can use any name you wish as long as you use the same name in both places.
Developing an ASP.NET program with Web Matrix is a huge step up from using Notepad. Web Matrix stores your program in a single file as Notepad does, but it provides four different views of your program, which you can select by choosing the appropriate tab at the bottom of the Document window.
The first view is the Design window, which allows you to design your Web form by dragging HTML elements and Web controls from the toolbox onto the Design window. Then, you can drag them around in the window and resize them graphically to create your Web page (see Figure 1). You can access the individual attributes for these elements and controls through the Properties window located in the lower-right corner of the Web Matrix development window.
Figure 1. You can drag and drop HTML elements and Web controls onto the Design window and size and arrange them graphically to create your Web page.
As you drag and drop information in the Design window, Web Matrix generates the underlying HTML code automatically, which you can edit in the HTML window. You can edit the HTML tags in the HTML window and then switch back to the Design window to see the effects of those changes. If you make changes in the Design window and switch back to the HTML windows, you will find the HTML tags are reformatted automatically. Based on comments I've heard from various Web Matrix users, either you'll find this feature useful or it will drive you insane. One reason many people prefer to use Notepad is because it does not rearrange your HTML tags automatically.
The third view of your program is found in the Code window. Web Matrix supports both Visual Basic and C# statements, although you can use only one language in the single file. One nice feature is if you double-click on a control in the Design window, Web Matrix will create a default event handler in the Code window automatically with all the proper arguments. For instance, if you double-click on the Button control, Web Matrix will create a Click event handler in the Code window. Then you can add your code to handle the Click event in the Button1_Click subroutine.
After you finish your program, you can select the All tab to display the All window, which shows the complete source code as it will exist on disk. Then you can choose View | Start or press F5 to run your program. This opens a new Web browser window with your ASP.NET program.
You can download Web Matrix at http://www.asp.net. It's only a 1.2 mb download, so even modem users can download a copy in less than five minutes.
Both Notepad and Web Matrix build ASP.NET applications using a single file. Both the HTML tags and the source code reside in the same file. Visual Studio .NET, on the other hand, uses a different approach. It stores the HTML tags in one file and your code in a second file. This technique is known as code-behind.
Code-behind programming relies on .NET's object-oriented nature, which permits one class to inherit all the features and functions of another class. In this case, the HTML file that has a file type of .aspx inherits the class defined in the source-code file, which has a file type of .aspx.vb. This lets you keep the code separate from the Web page's layout.
This technique offers significant advantages in larger organizations where the graphical portion of a Web page can be assigned to a Web page developer, while the code behind the page can be assigned to an ASP.NET programmer. This leaves the Web developer free to arrange the controls on the page without affecting the underlying code. Likewise, this gives the ASP.NET programmer the freedom to develop and maintain the code without being adversely affected by the Web developer.
Visual Studio .NET has two primary advantages over Notepad and Web Matrix. The first is IntelliSense, which makes writing code a snap. IntelliSense has complete access to the .NET Framework's object model, as well as all the objects defined in your application. As you type, IntelliSense attempts to recognize which object you are referencing and offers a list of properties and methods for you to choose from. You can scroll down the list of choices or continue typing characters until you reach the property or method desired. Pressing Enter, the Tab key, a space, a period, or a left parenthesis accepts the selected item and allows you to proceed (see Figure 2). IntelliSense also provides information for parameters, data-type definitions, and many other context-sensitive situations that help you write code faster and more accurately.
Figure 2. IntelliSense displays a list of choices for object properties and methods based on the object you're referencing and the statement you're typing.
Visual Studio .NET's second advantage over Notepad and Web Matrix is its integrated debugger, which allows you to examine the state of your application while it's running. Before you start your program, you can use the integrated debugger to set break points in your program and specify how it should handle run-time errors. When your program reaches a breakpoint or traps a run-time error, all processing is paused and you enter the interactive part of the debugger. There, you can examine the values in the various objects in your program interactively and change their values. When you have finished, you can continue execution or execute your program one line at a time. You even may call various methods to gather information. The only limitation to the debugging facility is you can't change the code while the program is running the way you could in Visual Basic 6.0.
Beyond the Basics
Both Visual Studio .NET and Web Matrix include many utilities that can make your life easier. Visual Studio .NET includes tools that help you edit Cascading Style Sheets (CSS) and XML documents, manage the source code in a multiprogrammer project, and create and use Web Services. In addition, Visual Studio .NET includes an extensive collection of database tools that allow you to create and edit database objects (such as tables and views), build SQL queries using a graphical interface, and code and debug stored procedures. Some of the tools are available only with the later (and more expensive) editions of Visual Studio .NET.
Some of Visual Studio .NET's capabilities also are available in Web Matrix, including the ability to create and use Web Services, edit XML documents, and edit and query SQL Server databases, although the Web Matrix versions of these features are less polished. Web Matrix has a few unique capabilities Visual Studio lacks, including the ability to deploy an application using File Transfer Protocol (FTP). Web Matrix also integrates many community features into the IDE, such as the ability to browse ASP.NET-related Web sites and search for information contained in the ASP.NET forums and newsgroups.
Because the only way to understand the benefits and drawbacks of each of these tools is to try to build a simple program with each one, your assignment is to create a Web page that accepts information from a text-box control and displays it in a label control whenever a button control is pressed. Creating the program once using one of the tools and pasting it into others would be easy, but that would be cheating. You should create each program from scratch to get the best feel for how each development tool works. You can download the solutions to this assignment.
The files referenced in this article are available for download.
Wayne S. Freeze is a full-time author with more than a dozen books to his credit, including Windows Game Programming with Visual Basic and DirectX (Que) and Unlocking OLAP with SQL Server and Excel 2000 (Hungry Minds). He has more than 25 years' experience using all types of computers, from small, embedded microprocessor control systems to large-scale IBM mainframes. Freeze has a master's degree in management information systems as well as degrees in computer science and engineering. You can visit his Web site at http://www.JustPC.com and e-mail him at mailto:[email protected].
Tell us what you think! Please send any comments about this article to [email protected]. Please include the article title and author.