Analyze the differences between ASP and ASP. NET

Source: Internet
Author: User

Differences between ASP and ASP. NET: Create an ASP page
1. Open Visual Studio. NET integrated development environment: Click Start, click Programs, click Experience VS. NET Content, click Lab 3, and click ASP Source. An empty asp page file named Authors. ASP is opened in Visual Studio. net ide, as shown in 1.


Figure 1 ASP page

2. Enter the following code:

 
 
  1. <%@ Language=VBScript %>  
  2. <HTML>  
  3. <HEAD>  
  4. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">  
  5. <STYLE>  
  6. BODY { font:arial }  
  7. H1 { color:navy }  
  8. </STYLE>  
  9. </HEAD>  
  10. <BODY>  
  11. <DIV align=center>  
  12. <H1>Authors</H1>  
  13.  
  14. <%  
  15. '  
  16. ' Connecting to a database  
  17. '  
  18. dim cn  
  19. set cn = server.CreateObject("ADODB.Connection")  
  20. cn.Open "Provider=sqloledb;" _  
  21. & "Data Source=(local);" _  
  22. & "Initial Catalog=pubs;" _  
  23. & "User ID=sa"  
  24. ' Retrieving Data via the Recordset Object.  
  25. dim rs  
  26. set rs = server.CreateObject("ADODB.Recordset")  
  27. rs.Open "select au_fname, au_lname, phone from authors order by au_lname",cn   
  28. %>  

Note:

The following code consists of static HTML and server-side scripts. It uses a loop to traverse all the data in the dataset (recordset.

 
 
  1. <TABLE border='1'>  
  2. <TR>  
  3. <TH>First Name</TH>  
  4. <TH>Last Name</TH>  
  5. <TH>Phone</TH>  
  6. </TR>  
  7. <%  
  8. do until rs.EOF  
  9. Response.Write "<TR>"  
  10. Response.Write "<TD>" & rs("au_fname") & "</TD>"  
  11. Response.Write "<TD>" & rs("au_lname") & "</TD>"  
  12. Response.Write "<TD>" & rs("phone") & "</TD>"  
  13. Response.Write "</TR>"  
  14. rs.MoveNext  
  15. loop  
  16. %>  
  17. </TABLE>  
  18.  
  19. <!-- Footer -->  
  20. <h5>Current as of <%Response.Write now%></h5>  
  21. </DIV>  
  22. </BODY>  
  23. </HTML>  

3. Click File and Save Authors. asp.

4. Disable IDE.

Differences between ASP and ASP. NET: viewing ASP pages
1. view ASP page: Click Start, Programs, Experience VS. NET Content, Lab 3, and ASP. The page shows 2.


Figure 2 result displayed on the ASP page

Differences between ASP and ASP. NET: Create an ASP. NET page
1. Open Visual Studio. net ide: Click Start, click Programs, click Experience VS. NET Content, click Lab 3, and then click ASP. net vb Source. An empty ASP. NET page file named Authors VB. aspx is opened in Visual Studio. net ide, as shown in 3.


Figure 3 ASP. NET page


2. Click the HTML button in the lower-left corner of the Visual Studio. NET window to view the Page code.

3. Enter the following code:

Note: System. Data and System. Data. SqlClient namespaces are declared at the top of the page. Therefore, all the classes in the two namespaces can be available on the following ASP. NET page.

 
 
  1. <%@ Import Namespace="System.Data" %>  
  2. <%@ Import Namespace="System.Data.SqlClient" %>  
  3.  
  4. <HTML>  
  5. <HEAD>  
  6. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">  
  7. <STYLE>  
  8. BODY { font:arial }  
  9. H1 { color:navy }  
  10. </STYLE>  
  11.  
  12. </HEAD>  
  13. <BODY>  
  14. <DIV align=center>  
  15. <H1>Authors</H1> 

Note: server scripts are completely separated from static HTML. You can use any run-time language, such as Microsoft Visual Basic ?, Microsoft? Jscript? And C #.

 
 
  1. < script language="VB" runat="server">  
  2.  
  3. Sub Page_Load(Src As Object, E As EventArgs)   
  4.  
  5. Dim DS As DataSet  
  6. Dim MyConnection As SQLConnection  
  7. Dim MyCommand As SQLDataAdapter  
  8.  
  9. MyConnection = New SQLConnection("server=localhost;uid=sa;pwd=;database=pubs")  
  10. MyCommand=New SQLDataAdapter("select au_fname as 'First Name', au_lname as 'Last Name',Phone from Authors",MyConnection)  

Note: The DataSet object in the following code replaces the Recordset object, and pay attention to the fill method in the SQLDataAdapter object.

 
 
  1. DS = new DataSet()  
  2. MyCommand.Fill(ds,"Authors ")

Note: The following Code sets the DataSource attribute of the DataGrid Control. Note that the Table set in the DataSet object is different from the Recordset object. The DataSet object can contain multiple tables.

 
 
  1. grdAuthors.DataSource=ds.Tables("Authors").DefaultView  

Note: In the following code, the DataGrid Control loads data using the DataBind method, and then the DataGrid Control displays data in the form of an HTML table.

 
 
  1. grdAuthors.DataBind()  
  2. End Sub  
  3. </script> 

Note: The first line of code below embeds a DataGrid object into the page. Other properties of the DataGrid Control can also be set by adding attribute/value pairs, for example, Width = "700" BackColor = "# ccccff ".

 
 
  1. <asp:DataGrid runat=server id=grdAuthors/>   
  2.  
  3. <!-- Footer -->  
  4. <h5>Current as of <%Response.Write (Now.ToString)%></h5>  
  5. </DIV>  
  6.  
  7. </BODY>  
  8. </HTML>  

4. Click File and Save Authors VB. aspx.

5. Disable IDE.

Differences between ASP and ASP. NET: viewing ASP. NET pages
1. view ASP. NET page: Click Start, click Programs, click Experience VS. NET Content, click Lab 3, and then click ASP.NET-VB. The page shows 4.


Figure 4 ASP. NET display page


End of Introduction to differences between ASP and ASP. NET
When you have finished viewing ASP. NET pages, close all windows.

  1. Analysis on ASP. NET Web Security
  2. Session State of ASP. NET
  3. Analysis on the attribute ASP. NET of IsPostBack
  4. ASP. NET architecture and security mechanism
  5. Overview ASP. NET Crystal Reports

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.