The Major Differences Between ASP and ASP.NET

only for RuBoard

Although ASP.NET appears to be similar to ASP from the developer's point of view, it's actually quite different. ASP.NET is entirely object-based; every object can have its own properties, methods , and events. This structure provides an object-oriented approach to developing Web applications. ASP.NET was developed to make Web application development simpler, richer, and more available to all developers. Some of the major differences between ASP and ASP.NET that you'll learn about in this book are as follows :

  • Strong-typed languages

  • ADO vs. ADO.NET

  • Server controls

  • XML and SOAP support

Strong-Typed Languages

ASP.NET enables you to write Web applications in a variety of strong-typed languages, such as C#, Managed C++, Visual Basic.NET, and others. In these languages, the framework recognizes the types that are important to the user of the application.

For example, in ASP you couldn't refer to a table of customer information by name , such as Customers . But strong-typed languages treat objects, such as tables, as types that can be referred to by name. In ASP.NET, you can assign the name Customers to a table and reference it programmatically, no matter what language you're developing in.

Strong-typed languages require a shift in thinking for the developer. In traditional scripting, the things that are important to the developer are emphasized , whereas in strong-typed languages, the types are what the end user is concerned with. Take the following, for example:

 AcctNum = Table("Customer").Cells("AccountNumber") 

Although the table and cells are important types to the developer, the end user is more concerned with the customer and account number information. With a strong-typed language, these elements are emphasized in the programming:

 AcctNum = Customer.AccountNumber 

You might have grown accustomed to using VBScript to code your ASP pages. VBScript is not a strong-typed language, however, but rather a scripting language. ASP.NET applications cannot be written in VBScript, but you can write them in Visual Basic.NET. Much of the syntax in VBScript is similar to that in Visual Basic.NET, but there are differences you will need to learn, such as declaring variable data types. If you prefer, you can write ASP.NET applications in a number of other languages.

Note

Throughout the book, you'll see samples in both C# and Visual Basic.NET. If you don't have a language preference yet, this book should give you a good idea of which one better suits you.


Additionally, you're no longer restricted to the linear processing model of ASP, in which page script was read from top to bottom. Instead, ASP.NET pages are compiled into objects. The compiled nature of an ASP.NET page allows you to programmatically reference an object, such as a server control, that's placed further down the page.

ADO vs. ADO.NET

With the release of the .NET Framework, Microsoft introduced ADO.NET, which is the next step in the natural evolution of Microsoft's data access technologies (from DAO to RDO to ADO). ADO.NET is a new way to develop data-driven applications. ADO was great for developing connected data applications, but it was not good at providing data in a disconnected method, such as that needed by ASP. If you wanted to transmit an ADO RecordSet from the data source to a COM object, all of the data types in the RecordSet had to be converted to data types that COM understood . This type of data marshalling came at a high processing cost.

ADO.NET is a disconnected, message-based data access model. Data from a data source, such as Microsoft SQL Server, can be transmitted and persisted as an XML document and will be accessible by any application that can parse XML. The data is disconnected from the originating data source and transmitted in an application-friendly format. As a result, the data types don't need to be converted from their native types to a COM-friendly data type. This saves you in the processing cost of marshalling that ADO did not. Additionally, any COM object that can parse XML can use the data without any hard conversions, and COM objects that cannot parse XML can still save the file or pass it to another COM object as if it were plain text.

In Chapter 2, "What Is ADO.NET?", you'll learn a lot more about the ADO.NET object model.

Note

Although you'll be using ADO.NET as your data access model in this book, you can still use ADO in ASP.NET. The drawback is that you don't get the added benefits that ADO.NET provides, such as direct connections to SQL Server, disconnected XML-based data and more.


Server Controls

In classic ASP, the developer had to write code to perform almost any function. A common function, such as validating user input, had to be written every time the developer wanted to implement it. In ASP.NET, server controls provide an easy replacement for this model. An array of ASP.NET's intrinsic controls provides commonly used functionality. A developer can create business solutions by placing these controls and altering their properties, quickly achieving the same results that required excessive code in classic ASP.

To validate user input in ASP, you had to write code similar to Listing 1.1.

Listing 1.1 The ASP Code for Validating User Input
 01: <html> 02: <head> 03: <title>Programming Datadriven Web Applications with ASP.NET - Chapter 1</title> 04: </head> 05: <body> 06: <% 07: Dim strName, strPrefix 08: strName = Request.Form("txtName") 09: strPrefix = Request.Form("selPrefix") 10: 11: If Request.Form.Count > 0 Then 12:   If Not Trim(strName) = "" Then 13: %> 14:   Hello <%=strPrefix%>&nbsp;<%=strName%><br> 15:   <%Else%> 16:   Please enter your name. 17:   <%End If%> 18: <%End If%> 19: 20: <form method="post" action="0101.asp"> 21: Name:<br> 22: <input type="text" name="txtName" value="<%=strName%>"><br> 23: 24: Prefix:<br> 25: <select name="selPrefix"> 26:   <option>--Select One--</option> 27:   <option <%If strPrefix = "Mr." Then%>selected<%End If%>>Mr.</option> 28:   <option <%If strPrefix = "Ms." Then%>selected<%End If%>>Ms.</option> 29:   <option <%If strPrefix = "Mrs." Then%>selected<%End If%>>Mrs.</option> 30: </select> 31: <p><input type="submit" value="Submit"></p> 32: </form> 33: </body> 34: </html> 

On line 11 you have an If...Then evaluation to check if the page is being loaded as the result of a form post. On line 12 you use another If...Then to check if the txtName field has something entered into it. If the txtName field is empty you render an error message to the screen, otherwise you render a welcome message. ASP.NET's server controls provide the same functionality without requiring you to write the code, as shown in Listing 1.2.

Listing 1.2 Required Field Validation with an ASP.NET Server Control
 [VB] 01: <script runat="server" language="VB"> 02:  Protected Sub Page_Load(Sender As Object, E As EventArgs) 03:   If Page.IsPostBack And Page.IsValid Then 04:    Welcome.Text = "Hello " & selPrefix.Value & " " & txtName.Text & "<br><br>" 05:   End If 06:  End Sub 07: </script> [C#] 01: <script runat="server" language="C#"> 02:  protected void Page_Load(object sender, EventArgs e){ 03:   if(Page.IsPostBack && Page.IsValid){ 04:    Welcome.Text = "Hello " + selPrefix.Value + " " + txtName.Text + "<br><br>"; 05:   } 06:  } 07: </script> [VB & C#] 08: <html> 09: <head> 10: <title>Programming Datadriven Web Applications with ASP.NET - Chapter 1</title> 11: </head> 12: <body> 13: <form runat="server" method="post"> 14:  <asp:Label runat="server" id="Welcome" /> 15:  <asp:TextBox runat="server" id="txtName" /> 16:  <asp:RequiredFieldValidator runat="server" 17:   ControlToValidate="txtName" 18:   ErrorMessage="Please enter your name." 19:   ForeColor="#CC3300" /> 20:  <br> 21:  Prefix:<br> 22:  <select id="selPrefix" runat="server"> 23:    <option>--Select One--</option> 24:    <option>Mr.</option> 25:    <option>Ms.</option> 26:    <option>Mrs.</option> 27:  </select> 28:  <asp:RequiredFieldValidator runat="server" 29:   ControlToValidate="selPrefix" 30:   InitialValue="--Select One--" 31:   ErrorMessage="Please select your prefix." 32:   ForeColor="#CC3300" /> 33:  <p><input type="submit" value="Submit" runat="server"></p> 34: </form> 35: </body> 36: </html> 

On lines 16 “19, you place the RequiredFieldValidator server control. This control is set to validate the input of the TextBox named txtName . An error message is displayed if the form is posted without a value in the TextBox .

On lines 28 “32 you do use the RequiredFieldValidator to validate the <select> list HtmlControl for a valid selection.

Figure 1.1 shows the output from Listing 1.2. When the form is posted without a value in the TextBox and an inappropriate selection in the <select> list, the RequiredFieldValidator controls display the error message "Please enter your name." and "Please select your prefix."

Figure 1.1. By using an ASP.NET server control, you can validate user input without having to write excessive code.
graphics/01fig01.gif

ASP.NET server controls let you use familiar HTML-style controls to provide functionality that previously required you to write code. This simplifies and speeds up the development process because the functionality is prebuilt and is bulletproof in most cases.

XML and SOAP Support

Extensible Markup Language (XML), a text-based, self-describing language derived from Standard Generalized Markup Language (SGML), is important in today's development environment. No matter what platform you're using, XML lets you open , read, and save data in a non-proprietary text format, making it a viable medium for transmitting that data. ASP.NET and ADO.NET use XML as the persistence and transmission format for data. As a result, ASP.NET applications can work with virtually any data source and interact with existing COM components .

Simple Object Access Protocol (SOAP) is an HTTP-based protocol used for exchanging structured and typed information on the Web, such as XML. Once received, this type of functionality requires an XML parser to convert the data to an XML file before the end user can use that data. In the past, creating these types of applications was very tedious and complicated.

ASP.NET Web services use XML as their data format and SOAP as their protocol, making this type of application much easier. You'll learn more about Web services later in this chapter. In Chapter 12, "XML and SOAP," you'll learn more about how ASP.NET uses both XML and SOAP. You'll dive headfirst into Web services in Chapter 14, "Exposing Data Through a Web Service."

only for RuBoard


Programming Data-Driven Web Applications with ASP. NET
Programming Data-Driven Web Applications with ASP.NET
ISBN: 0672321068
EAN: 2147483647
Year: 2000
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net