ASP.NET - Web page
- Προηγούμενη Σελίδα Εισαγωγή στο WebForms
- Επόμενη Σελίδα έλεγχοι WebForms
A simple ASP.NET page looks similar to a common 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 this HTML file as a new file with the .aspx suffix.
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.
The extension of HTML pages is .htm or .html. If the browser requests an HTML page from the server, the server will send the page to the browser without any modification.
The extension of ASP.NET pages is .aspx. If the 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. Through 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 does not fully comply with Classic ASP, but with a few modifications, Classic ASP can work well as ASP.NET.
Αν θέλετε να μάθετε περισσότερα για το Classic ASP, επισκεφθείτε τον ιστότοπό μας. Εκμάθηση ASP.
Δυναμική Σελίδα γραμμένη με Classic ASP
Για να σας δείξουμε πώς να χρησιμοποιήσετε δυναμικό περιεχόμενο για να εμφανίσετε τη σελίδα, προσθέσαμε μερικό εκτελέσιμο κώδικα στο παραπάνω παράδειγμα:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> <p><%Response.Write(now())%></p> </body> </html>
Ο κώδικας μέσα στις ετικέτες <% --%> εκτελείται στον διακομιστή.
Το Response.Write είναι κώδικας ASP που χρησιμοποιείται για να βάλει κείμενο στο ροή HTML.
Η Now() είναι μια συνάρτηση που μπορεί να επιστρέψει την τρέχουσα ημερομηνία και ώρα του διακομιστή.
Αν θέλετε να δοκιμάσετε προσωπικά, αποθηκεύστε αυτόν τον κώδικα σε ένα αρχείο με το όνομα "dynpage.asp" και δημιουργήστε έναν σύνδεσμο προς αυτό το αρχείο:dynpage.asp.
Δυναμική Σελίδα γραμμένη με ASP .NET
Ο παρακάτω κώδικας μπορεί να εμφανίσει το παράδειγμα μας ως σελίδα ASP.NET:
<html> <body style="background-color:#e5eecc; text-align:center;"> <h2>Hello CodeW3C.com!</h2> <p><%Response.Write(now())%></p> </body> </html>
Αν θέλετε να δοκιμάσετε προσωπικά, αποθηκεύστε αυτόν τον κώδικα σε ένα αρχείο με το όνομα "dynpage.aspx" και δημιουργήστε έναν σύνδεσμο προς αυτό το αρχείο:dynpage.aspx.
ASP.NET κ.λπ. ASP
Οι παραπάνω παραδείγματα δεν μπορούν να δείξουν τις διαφορές μεταξύ ASP.NET και Classic ASP.
Καθώς είδατε στους τελευταίους δύο παραδείγματα, δεν υπάρχει καμία διαφορά μεταξύ αυτών των δύο σελίδων ASP και ASP.NET.
Στα παρακάτω κεφάλαια θα δείτε πώς οι ελεγχόμενοι διακομιστές κάνουν το ASP.NET πιο ισχυρό από το Classic ASP.
- Προηγούμενη Σελίδα Εισαγωγή στο WebForms
- Επόμενη Σελίδα έλεγχοι WebForms