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.
- Open the Web Form to the markup view.
- 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" %>
- Remove the following
@Register directives:
<%@ Register TagPrefix="HeaderTag"
TagName="Header" Src="include/Header.ascx" %>
<%@ Register TagPrefix="FooterTag"
TagName="Footer" Src="include/Footer.ascx" %>
- Remove the following HTML tags:
- <!DOCTYPE…>
- <html>
- <head>
- <title>
- <link>
- <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)
- </head>
- Below the @Page directive,
add a Content Place Holder for the HTML head:
<asp:Content ID="Content1"
ContentPlaceHolderID="head" runat="server">
</asp:Content>
- Copy anything particular to this page (not common to the site) to the Content Place Holder created in the previous step.
- Remove the following HTML tags:
- <body>
- </body>
- </html>
- plus any form tags, unless those form tags point to a different form; we will deal with these later
- 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">
- 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>
- 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
- 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
Post a Comment