Chapter 2. Hello World

The previous chapter introduced the ASP.NET architecture. In future chapters, you will learn all about creating web applications with ASP.NET. The current chapter presents a whirlwind tour by creating a simple web page to show you how easy it can be.

It is a long-standing tradition among programmers to begin the study of a new language by writing a program that prints “Hello World” to the screen. In deference to tradition, our first web page will do just that.

The tool you are most likely to use when developing ASP.NET applications is an integrated development environment (IDE), such as Visual Studio .NET. You may use any editor you like, however -- even the venerable text editor Notepad.

There are a number of advantages to using an IDE such as Visual Studio .NET. The Visual Studio .NET editor provides indentation and color coding of your source code, the IntelliSense feature helps you choose the right commands and attributes, and the integrated debugger helps you find and fix errors in your code.

The disadvantage of using an IDE, however, is that it may do so much work for you that you don’t get a good feel for what is going on in your application. It is like bringing your car in to the mechanic; he does all the work for you, but you never really learn how your engine works.

As a beginner, you may be better off doing more of the work yourself, giving up the support of the IDE in exchange for the opportunity to see how things really work. In this chapter, you will use a simple text editor to create the source code for the first several iterations. At the end of the chapter, you will use Visual Studio .NET to create the same web page. (For the remainder of the book, you will find both examples that are created using a text editor and examples that are developed in Visual Studio .NET.)

Back in the old days, before ASP and ASP.NET, web pages were created with simple HTML. To better appreciate the features of ASP.NET, you will first create the Hello World web page in HTML, then convert it to ASP, and finally convert it to ASP.NET.

The HTML Version

Straight HTML provides a means of creating and presenting static web pages. This book is not a tutorial on how to write HTML, and we assume you know enough HTML to follow the simple examples provided. (For background reading, see HTML: The Definitive Guide ,by Chuck Musciano and Bill Kennedy, published by O’Reilly.) To get started, create a very simple Hello World HTML file, as shown in Example 2-1, and call it HelloWorld1.htm. The output is shown in Figure 2-1.

Example 2-1. Code listing for HelloWorld1.htm

<html>
   <body>

      <h1>Hello World</h1>

   </body>
</html>
Output from Example 2-1

Figure 2-1. Output from Example 2-1

The HTML page displays the static text, using the HTML heading1 format. If you want to include dynamic content, such as the results of a query against a database, or even the current time, then a static HTML page is not the thing to use. For that you need some sort of server processing. There are a number of alternatives; we will focus on ASP and then on ASP.NET.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.93.0