ASP.NET Web Forms - HTML page
This section explains the writing of ASP.NET pages and briefly compares it with the writing of HTML pages.
Simple ASP.NET pages look like ordinary HTML pages.
Before starting to learn ASP.NET, let's first build a simple HTML page that will display "Hello w3cschool.cn" in the browser:
Hello w3cschool.cn! |
The following code will display the instance as an HTML page:
<html><body bgcolor="yellow"><center><h2>Hello w3cschool.cn!</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 the file: firstpage.htm.
The easiest way to convert an HTML page to 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 instance as an ASP.NET page:
<html><body bgcolor="yellow"><center><h2>Hello w3cschool.cn!</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.
Fundamentally, ASP.NET pages are exactly the same as HTML.
The extension of an 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 for 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 differences between static HTML pages and dynamic ASP pages.
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 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.
To demonstrate how ASP displays pages containing dynamic content, we will add some executable code (marked in red font) to the above example:
<html><body bgcolor="yellow"><center><h2>Hello w3cschool.cn!</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 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 above code to a file called " dynpage.asp " and create a link to the file: dynpage.asp.
The following code will display the instance as an ASP.NET page:
<html><body bgcolor="yellow"><center><h2>Hello w3cschool.cn!</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.
The above example does not 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.