A simple ASP.NET page looks just like a normal HTML page.
Hello RUNOOB.COM
Before we start learning ASP.NET, we first build a simple HTML page, which will display "Hello RUNOOB.COM" in the browser ":
Hello RUNOOB.COM!
|
##
Hello RUNOOB.COM written in HTML
The following code will display the example as an HTML page:
<html>
<body bgcolor="yellow">
<center>
<h2>Hello RUNOOB.COM!</h2>
</center>
</body> ;
</html>
If you want to try it yourself, save the above code to a file called "firstpage.htm" and Create a link to this file: firstpage.htm.
Hello RUNOOB.COM written in ASP.NET
The easiest way to convert an HTML page to an ASP.NET page is to directly copy an HTML file and put the Change the extension to .aspx.
The following code will display the instance as an ASP.NET page:
<html>
<body bgcolor="yellow">
< ;center>
<h2>Hello RUNOOB.COM!</h2>
</center>
</body>
</html>
If you want to try it yourself, save the above code to a file called "firstpage.aspx" and create a link to the file: firstpage.aspx.
How does it work?
Fundamentally speaking, ASP.NET pages are exactly the same as HTML.
The extension of HTML page is .htm. If the browser requests an HTML page from the server, the server can send the page directly to the browser without making any modifications.
The extension of ASP.NET pages is .aspx. If the browser requests an ASP.NET page from the server, the server needs to process the executable code in the page before sending the results back to the browser.
The above ASP.NET page does not contain any executable code, so nothing is executed. In the following example, 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) were often referred to as 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.
Dynamic pages written in classic ASP
To demonstrate how ASP displays pages containing dynamic content, we will add some executable code (red font) to the above example Logo):
<html>
<body bgcolor="yellow">
<center>
<h2>Hello RUNOOB.COM!< /h2>
<p><%Response.Write(now())%></p>
</center>
</body> ;
</html>
<% --%> The code within the tag is executed on the server.
Response.Write is ASP code used to write things 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 above code to a file called "dynpage.asp" and create a link to the file: dynpage.asp.
Dynamic pages written in ASP .NET
The following code will display the example in the form of an ASP.NET page:
<html>
<body bgcolor="yellow">
<center>
<h2>Hello RUNOOB.COM!</h2>
<p><% Response.Write(now())%></p>
</center>
</body>
</html>
If you want to try it yourself, save the above code to a file called "dynpage.aspx" and create a link to the file: dynpage.aspx.
ASP.NET vs. Classic ASP
The above example cannot demonstrate any differences between ASP.NET and classic ASP.
As in the last two examples, you can't tell the difference between the ASP page and the ASP.NET page.
In the next chapter, you'll see how server controls make ASP.NET more powerful than classic ASP.