ASP.NET: Converting Web Forms to Content Pages

This is for my own reference while we convert some old sites to shiny new stuff. But, other people might find this useful.

Every web page in the site was created as an ASP.NET Web Form. No Master Pages were used. To ensure a consistent look-and-feel and consolidate common pieces of code (such as the code that checks whether or not a user is logged in), the Web Forms should be converted to Content Pages.

Follow the steps below to convert an existing Web Form to a new Content Page.

  1. Open the Web Form to the markup view.
  1. Add the following to the @Page directive at the top of the form:

    MasterPageFile="~/Site.Master"

    The resulting @Page directive should look something like this:

    <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Logon.aspx.vb" Inherits="SGBP.Logon" %>
     
  2. Remove the following @Register directives:

     
<%@ Register TagPrefix="HeaderTag" TagName="Header" Src="include/Header.ascx" %>
<%@ Register TagPrefix="FooterTag" TagName="Footer" Src="include/Footer.ascx" %>
 
  1. Remove the following HTML tags:
    1.  <!DOCTYPE…>
    1. <html>
    1. <head>
    2. <title>
    1. <link>
    2. <style> (unless the style is particular to this Web Form; in this case, copy the <style> tag to the Content Place Holder, created in the next step)
    3. </head>
  1. Below the @Page directive, add a Content Place Holder for the HTML head:
     
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
   
</asp:Content>
 
  1. Copy anything particular to this page (not common to the site) to the Content Place  Holder created in the previous step.
  2. Remove the following HTML tags:
    1. <body>
    2. </body>
    3. </html>
    1. plus any form tags, unless those form tags point to a different form; we will deal with these later
  1. Below the Content Place Holder created in Step 4, above, add a second Content Place Holder for the body of the Web Form:

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
     
  2. Add the closing tag for the Content Place Holder at the very bottom of the page (where the </body> and </html> tags used to be:

    </asp:Content>
     
  1. Review the form and consider replacing any <input type="button"…> HTML tags with the appropriate <asp:…> control. In many cases, you can leave <input type="submit"…"> tags in place and they will
  1. Save the page and test it.


If there were <form> tags in the original Web Form and they pointed to other Web Forms, then you will have to add the login

Comments

Popular posts from this blog

Using Reference Aliases

List of Visual Studio Keyboard Shortcuts