To read the article online, visit http://www.4GuysFromRolla.com/webtech/041601-1.shtml

Preparing your ASP Pages for a Transition to ASP.NET

By Darren Neimke and Scott Mitchell


About this Article
This article briefly examines the design and development changes in ASP.NET from classic ASP. (For those who are unaware, ASP.NET is Microsoft's next "version" of ASP. If you are unfamiliar with ASP.NET it is highly recommended that you read some of the introduction articles at the ASP.NET Article Index.) This article focuses on looking at how to write your ASP code today to make it easier to port the ASP code you write today into future ASP.NET code.

Also keep in mind that both ASP and ASP.NET can run simultaneously on a Web server. When moving to ASP.NET you are not required to migrate all of your ASP pages to ASP.NET pages. However, you may wish to due to ASP.NET's enhanced performance and better code maintainability and readability over classic ASP.

Introduction
One of the biggest changes developers migrating from classic ASP to ASP.NET will have to deal with is ASP.NET's radical shift in the way dynamic Web pages are built. ASP pages consist of interpretted script code often presented in procedural terms. The script begins processing the first line of code in the ASP page and works its way down. The code in an ASP page is used, essentially, to directly fiddle and customize the HTML that is sent to the client (the Web visitor's browser).

With ASP.NET, however, dynamic Web pages are compiled programs adhering to object-oriented programs methodologies. While ASP.NET pages can simply use blocks of HTML like classic ASP page, ASP.NET encourage the use of Web controls, which are black-box type server-side tags that produce HTML. For example, with classic ASP one would create a simple postback form that outputs the user's entries with the following code:

<%
  If Len(Request("btnSubmit")) > 0 then
	Response.Write "Hello, " & Request("txtName") & "<p>"
  End If
%>
<form method="post" action="<%=Request.ServerVariables("URL")%>">
  What is your name?<br>
  <input type="text" name="txtName" value="<%=Request("txtName")%>">
  <p>
  <input type="submit" value="See your Welcome Message!">
</form>

Note the intricate mixing of HTML and ASP code (such as in the value parameter in the txtName INPUT tag). The corresponding ASP.NET page, utilizing Web controls (sometimes referred to as server controls), would be much cleaner and simpler:

<script language="vb" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    lblWelcomeMessage.Text = "Hello, " & txtName.Text
  End Sub
</script>

<asp:label id="lblWelcomeMessage" runat="server" />

<form runat="server">
  What is your name?<br>
  <asp:textbox runat="server" id="txtName" />
  <p>
  <asp:button id="btnSubmit" runat="server"
            Text="See your Welcome Message!" />
</form>  

Note the many fundamental stylistic coding differences in the ASP.NET example as compared to the classic ASP example. Execution of the ASP page begins with the first line of code; execution of the ASP.NET page begins with the Page_Load event handler. The ASP.NET page utilizes Web controls while the ASP page shamelessly mixes code and content.

This article, however, is not intended to present the differences among classic ASP and ASP.NET. To learn more about these fundamental differences check out: Transitioning to ASP.NET: Server Controls. This article examines, in detail, server controls, and how they can and should be used in an ASP.NET page. Also be sure to check out the many great articles listed in the 4Guys ASP.NET Article Index.

Now that we've looked at ASP.NET's anatomy and compared that to classic ASP's anatomy, you may be wondering, "How do I get my classic ASP code ready to upgrade to .NET?" Due to these major differences between ASP and ASP.NET, simply renaming an ASP page from .asp to .aspx (the extension for ASP.NET pages) will rarely produce error-free code. Since, at the time of this article's writing (April 16th, 2001), ASP.NET is still in Public Beta 1, you may be hesitant on starting ASP.NET development. However, it would be very wise to start writing your classic ASP pages in a format that makes it easier to transition to ASP.NET once ASP.NET concludes beta testing.

In Part 2 we will look at what, specifically, we need to change when creating ASP pages today to make our migration to ASP.NET simpler.

  • Read Part 2!


  • Article Information
    Article Title: Preparing your ASP Pages for a Transition to ASP.NET
    Article Author: Darren Neimke and Scott Mitchell
    Published Date: Monday, April 16, 2001
    Article URL: http://www.4GuysFromRolla.com/webtech/041601-1.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers