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.
2. Enter the following code:
- <%@ Language=VBScript %>
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
- <STYLE>
- BODY { font:arial }
- H1 { color:navy }
- </STYLE>
- </HEAD>
- <BODY>
- <DIV align=center>
- <H1>Authors</H1>
-
- <%
- '
- ' Connecting to a database
- '
- dim cn
- set cn = server.CreateObject("ADODB.Connection")
- cn.Open "Provider=sqloledb;" _
- & "Data Source=(local);" _
- & "Initial Catalog=pubs;" _
- & "User ID=sa"
- ' Retrieving Data via the Recordset Object.
- dim rs
- set rs = server.CreateObject("ADODB.Recordset")
- rs.Open "select au_fname, au_lname, phone from authors order by au_lname",cn
- %>
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.
- <TABLE border='1'>
- <TR>
- <TH>First Name</TH>
- <TH>Last Name</TH>
- <TH>Phone</TH>
- </TR>
- <%
- do until rs.EOF
- Response.Write "<TR>"
- Response.Write "<TD>" & rs("au_fname") & "</TD>"
- Response.Write "<TD>" & rs("au_lname") & "</TD>"
- Response.Write "<TD>" & rs("phone") & "</TD>"
- Response.Write "</TR>"
- rs.MoveNext
- loop
- %>
- </TABLE>
-
- <!-- Footer -->
- <h5>Current as of <%Response.Write now%></h5>
- </DIV>
- </BODY>
- </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.
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.
- <%@ Import Namespace="System.Data" %>
- <%@ Import Namespace="System.Data.SqlClient" %>
-
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
- <STYLE>
- BODY { font:arial }
- H1 { color:navy }
- </STYLE>
-
- </HEAD>
- <BODY>
- <DIV align=center>
- <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 #.
- < script language="VB" runat="server">
-
- Sub Page_Load(Src As Object, E As EventArgs)
-
- Dim DS As DataSet
- Dim MyConnection As SQLConnection
- Dim MyCommand As SQLDataAdapter
-
- MyConnection = New SQLConnection("server=localhost;uid=sa;pwd=;database=pubs")
- 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.
- DS = new DataSet()
- 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.
- 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.
- grdAuthors.DataBind()
- End Sub
- </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 ".
- <asp:DataGrid runat=server id=grdAuthors/>
-
- <!-- Footer -->
- <h5>Current as of <%Response.Write (Now.ToString)%></h5>
- </DIV>
-
- </BODY>
- </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.
- Analysis on ASP. NET Web Security
- Session State of ASP. NET
- Analysis on the attribute ASP. NET of IsPostBack
- ASP. NET architecture and security mechanism
- Overview ASP. NET Crystal Reports