ASP.NET - Web page
- Previous Page WebForms Introduction
- Next Page WebForms Control
A simple ASP.NET page looks similar to a regular HTML page.
Hello CodeW3C.com
To begin our ASP.NET learning journey, we will first construct a simple HTML page that will display "Hello CodeW3C.com" in the browser:
Hello CodeW3C.com
Hello CodeW3C.com written in HTML
The HTML code of this HTML page:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> </body> </html>
If you want to try it yourself, you can save this code in a file named "firstpage.html" and create a link to this file, like this:firstpage.html.
Hello CodeW3C.com written in ASP.NET
The simplest way to convert an HTML page to ASP.NET is to copy the HTML file as a new file with the .aspx extension.
These will display our example as an ASP.NET page:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> </body> </html>
If you want to try it yourself, please save this code in a file named "firstpage.aspx" and create a link to this file:firstpage.aspx.
How does it work?
Fundamentally, ASP.NET pages are completely the same as HTML pages.
The extension for HTML pages is .htm or .html. If a browser requests an HTML page from the server, the server will send the page to the browser without any modification.
The extension for ASP.NET pages is .aspx. If a browser requests an ASP.NET page, the server will first process the executable code in the page before sending the result back to the browser.
The above ASP.NET page does not contain any executable code, so it will not execute any code. In the following example, we will add some executable code to the page to demonstrate the difference between static HTML pages and dynamic ASP pages.
Classic ASP
Active Server Pages (ASP) have been popular for many years. With ASP, executable code can be placed inside HTML pages.
The ASP versions before ASP.NET are often referred to as Classic ASP (Classic ASP).
ASP.NET is not fully compatible with Classic ASP, but with a few modifications, Classic ASP can work well as ASP.NET.
If you want to learn more about Classic ASP, please visit our ASP Tutorial.
Dynamic Page Written in Classic ASP
To demonstrate how to use dynamic content to display a page, we have added some executable code to the above example:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> <p><%Response.Write(now())%></p> </body> </html>
The code within the <% --%> tags is executed on the server.
Response.Write is ASP code used to output text to the HTML output stream.
Now() is a function that can return the current date and time of the server.
If you want to try it yourself, save this code in a file named "dynpage.asp" and create a link to this file:dynpage.asp.
Dynamic Page Written in ASP .NET
The following code can display our example as an ASP.NET page:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> <p><%Response.Write(now())%></p> </body> </html>
If you want to try it yourself, save this code in a file named "dynpage.aspx" and create a link to this file:dynpage.aspx.
ASP.NET vs Classic ASP
The above example does not show the differences between ASP.NET and Classic ASP.
As you can see in the last two examples, there is no difference between these two ASP and ASP.NET pages.
In the following chapters, you will see how server controls make ASP.NET more powerful than Classic ASP.
- Previous Page WebForms Introduction
- Next Page WebForms Control