Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET Web Pages

ASP.NET Web Forms - HTML Pages


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


Hello RUNOOB.COM

Before we start learning ASP.NET, let's build a simple HTML page that displays "Hello RUNOOB.COM" in the browser:

Hello RUNOOB.COM!


Hello RUNOOB.COM written in HTML

The code below displays the example as an HTML page:

Hello RUNOOB.COM!

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


Hello RUNOOB.COM written in ASP.NET

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

The code below displays the example as an ASP.NET page:

Hello RUNOOB.COM!

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


How does it work?

Fundamentally, an ASP.NET page is exactly the same as HTML.

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

The extension of an ASP.NET page is .aspx. If a browser requests an ASP.NET page from a server, the server must 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.

Previous versions of ASP (before ASP.NET) are usually called classic ASP.

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

If you want to learn more about classic ASP, please visit our ASP Tutorial。


A 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) to the example above:

Hello RUNOOB.COM!

<%Response.Write(now())%>

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 server's current date and time.

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


A Dynamic Page Written in ASP.NET

The code below displays the example as an ASP.NET page:

Hello RUNOOB.COM!

<%Response.Write(now())%>

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


ASP.NET vs Classic ASP

The example above cannot demonstrate any difference between ASP.NET and classic ASP.

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

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