Export (0) Print
Expand All

Migrating ASP Pages to Web Forms Pages

Visual Studio .NET 2003

You can work with and run existing ASP pages (.asp files) as-is in Visual Studio. You can use ASP pages and ASP.NET pages in the same project. You can edit ASP files in the Web Forms Designer and run them as you would other pages in your project.

Note   Some ASP and Visual InterDev 6.0 features are not supported by ASP.NET, because these features require a different run-time environment. For more information, see Migrating ASP Pages to ASP.NET.

However, you might find it useful to convert ASP pages to ASP.NET Web Forms pages so that you can take advantage of the enhanced features of the newer architecture, including the benefits of using ASP.NET server controls and better performance and scaling.

Migrating an ASP page to a Web Forms page accomplishes the following:

  • Creates the proper file extension for the page.
  • At your option, generates a code-behind class file for the page.
  • Corrects certain HTML syntax that was allowed in ASP files but is not allowed in Web Forms pages. For example, the Web Forms Designer will put quotation marks around any ASP code used to set attribute values in an element.
  • Adds the appropriate page directives to the page so that it is linked with the code-behind file. For details, see @ Page.

The migration does not do the following:

  • Convert inline ASP code (delimited with <% and %>) to code in the class file. However, the existing ASP code will work properly when the page runs.
  • Convert VBScript code to Visual Basic .NET. You will need to fix errors that arise out of syntax problems, as documented below.
  • Convert Visual InterDev design-time controls (DTCs) to Web Forms controls. If you have a DTC on the page, Visual Studio substitutes a placeholder. The DTC will not operate at run time. It is recommended that you replace DTCs with ASP.NET server controls.
  • Convert existing HTML elements to HTML server controls or Web server controls. You can perform this step manually after the migration, as noted below.
  • Configure the page to be able to run COM+ 1.0 components. You can enable COM interoperability by setting the ASPCompat attribute of the page's @ Page directive. For resources that discuss COM interoperability, see "Additional Information" below.
  • Convert ADO data access code to ADO.NET. Using ADO in a Web Forms page requires COM interoperability. (See previous point.) For resources, see "Additional Information" below.

When the migration is complete, you can run the page normally. Generally, however, after performing the migration you will want to do further work on the page, such as substituting ASP.NET server controls for existing HTML elements.

To migrate an ASP page into a Web Forms project

  1. In Solution Explorer right-click the project, point to Add, then click Add Existing Item.
  2. In the Add Existing Item dialog box, find the ASP page to migrate, then choose Open.
    Tip   In the Files of type box, select Web Files to view all Web files.

    When you migrate the file, it is physically copied from the file's original location to the location of your Web Forms project, and it appears in Solution Explorer.

  3. In Solution Explorer, right-click the file name, choose Rename, and change the file name extension to ".aspx".

    This causes two confirmation dialog boxes to appear, one after the other.

  4. Do the following:
    1. The first dialog box notes that changing the file name extension may invalidate the file format for use with some applications. Click Yes.
    2. The second dialog box indicates that there is no code-behind class file associated with the new .aspx file. Click Yes to add the code-behind class file.
      Tip   You can click the Show All Files button in Solution Explorer to see all the files associated with this project. If you expand the tree below your newly migrated file, you should see the code-behind class file.
  5. Open the new .aspx file.

    By default, the file opens in Design view. If there are syntax errors on the page, the designer will open the file in HTML view. In that case:

    1. Try switching to Design view. It will not be displayed; instead you will see a message indicating syntax errors.
    2. Fix the errors and try switching to Design view again.
      Note   By default, switching between views causes the Web Forms Designer to apply automatic formatting. This can fix some syntax errors, such as missing quotation marks. For details, see Format, HTML/XML, Text Editor, Options Dialog Box.
  6. In HTML view, inspect the file to ensure that the file contains an HTML <form> element within the HTML <body> tags. If not, add a <form> element. In the opening tag, add the Runat = "server" attribute so that it looks similar to the following:
    <form id="Form1" method="post" runat="server">
  7. Determine whether the file contains calls to COM components — for example, ADO code. If so, add the AspCompat attribute to the page directive in HTML view:
    <%@ Page [...] AutoEventWireup="false" AspCompat="true" %>
  8. Save the form, compile the project, and view the page in the browser. For details see Compiling and Running Web Forms Pages.
  9. Check for issues that appear in the Task List window and resolve them. For more information see Task List Window.
  10. Repeat Steps 8 and 9 until your form is working properly.

At this point, you will not have any server controls on the page. However, you can convert existing HTML controls to HTML server controls. For details, see Converting HTML Server Controls to HTML Elements.

You only need to migrate the controls that you want to be accessible to server code during run time. The HTML controls that you do not migrate will behave as before.

Note   If you wish to add additional ASP.NET server controls to your newly migrated Web Forms page, you must close the file and open it again for the Web Forms Designer to properly initialize the Web Forms tab of the Toolbox. You may then drag server controls to your Web Forms page.

Additional Information

This topic offers only an overview of how to convert ASP pages to Web Forms pages. For more information, including language issues, COM compatibility, and more, see the following sources:

See Also

Migrating to Web Forms | Introduction to ASP.NET Server Controls | Creating and Managing Web Forms Pages

© 2014 Microsoft