ASP.NET Web Forms - HTML page


A simple ASP.NET page looks just like an ordinary HTML page.


Hello example.com

Before we start learning ASP.NET, let's build a simple HTML page that will display "Hello example.com" in the browser:

Hello example.com!



Hello example.com written in HTML

The following code will display the example as an HTML page:

<html>
<body bgcolor="yellow">
<center>
<h2>Hello example.com!</h2>
</center>
</body>
</html>

If you want to try it yourself, save the code above to a file named "firstpage.htm" file, and create a link to that file:firstpage.htm。


Hello example.com written in ASP.NET

The simplest way to convert an HTML page into an ASP.NET page is to copy an HTML file directly and change the extension of the new file to.aspx 。

The following code will display the example as an ASP.NET page:

<html>
<body bgcolor="yellow">
<center>
<h2>Hello example.com!</h2>
</center>
</body>
</html>

If you want to try it yourself, save the code above to a file named "firstpage.aspx" file, and create a link to that file:firstpage.aspx。


How does it work?

Fundamentally, ASP.NET pages are exactly the same as HTML.

The extension of an HTML page is .htm. If a browser requests an HTML page from the server, the server can send the page to the browser without making any modifications.

The extension of an ASP.NET page is .aspx. If a browser requests an ASP.NET page from the server, the server needs to process the executable code in the page before sending the result back to the browser.

The ASP.NET page above does not contain any executable code, so nothing is executed. In the example below, we will add some executable code to the page to demonstrate the difference between a static HTML page and a dynamic ASP page.


Classic ASP

Active Server Pages (ASP) has been popular for many years. With ASP, you can place executable code in HTML pages.

The earlier versions of ASP (before ASP.NET) are often called Classic ASP.

ASP.NET is not fully compatible with Classic ASP, but most Classic ASP pages can run well as ASP.NET pages with only a few modifications.

If you want to learn more about Classic ASP, please visit ourASP Tutorial。


Dynamic page written in Classic ASP

To demonstrate how ASP displays a page containing dynamic content, we will add some executable code (marked in red font) to the example above:

<html>
<body bgcolor="yellow">
<center>
<h2>Hello example.com!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

The code inside the <% --%> tags is executed on the server.

Response.Write is ASP code used to write something to the HTML output stream.

Now() is a function that returns the current date and time of the server.

If you want to try it yourself, save the code above to a file named "dynpage.asp" file, and create a link to that file:dynpage.asp。


Dynamic page written in ASP.NET

The following code will display the example as an ASP.NET page:

<html>
<body bgcolor="yellow">
<center>
<h2>Hello example.com!</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

If you want to try it yourself, save the code above to a file named "dynpage.aspx" file, and create a link to that file:dynpage.aspx。


ASP.NET vs Classic ASP

The example above cannot demonstrate any differences between ASP.NET and Classic ASP.

As in the last two examples, you cannot see any differences between the ASP page and the ASP.NET page.

In the next chapter, you will see how server controls make ASP.NET more powerful than Classic ASP.


Other Extensions