Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Merging a Code-Behind File into Its APX File

RSS
Modified on Wed, Apr 17, 2013, 4:31 PM by Administrator Categorized as ASP·NET Web Forms

Procedure

1. Remove the Inherits attribute from the Page directive.

2. Copy the contents of the class (NOT INCLUDING the public class line) into a <script runat='server' language='C#'> block.

3. Convert all the using statements in the code-behind file into <%@ Import namespace="value" %> directives in the ASPX file.

Example

Before (separate files)

ASPX Code

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" 
    Inherits="Acme.Web.Reports.ReportBrowser"
    %>

ASPX.CS Code

namespace Acme.Web.Reports
{
    public partial class ReportBrowser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        . . .
        }
    }
}

After (single ASPX file)

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" 
    %>

. . .

<%@ Import namespace="System" %>
<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="System.Linq" %>
<%@ Import namespace="System.Web" %>
<%@ Import namespace="System.Web.UI" %>
<%@ Import namespace="System.Web.UI.WebControls" %>
. . .

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
. . .
}
</script>

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.