Click here to Skip to main content
15,891,423 members
Articles / Web Development / ASP.NET

ASP.NET Page Templates - Using Inheritance

Rate me:
Please Sign up or sign in to vote.
4.76/5 (135 votes)
19 Sep 20028 min read 1.4M   11.8K   304  
A tutorial showing how to create page templates that use object-oriented inheritance.
<VisualStudioProject>
    <CSHARP
        ProjectType = "Web"
        ProductVersion = "7.0.9466"
        SchemaVersion = "1.0"
        ProjectGuid = "{2EB6670D-C397-4E08-A538-1BEEAD80CED0}"
    >
        <Build>
            <Settings
                ApplicationIcon = ""
                AssemblyKeyContainerName = ""
                AssemblyName = "PageInheritanceSample"
                AssemblyOriginatorKeyFile = ""
                DefaultClientScript = "JScript"
                DefaultHTMLPageLayout = "Grid"
                DefaultTargetSchema = "IE50"
                DelaySign = "false"
                OutputType = "Library"
                RootNamespace = "PageInheritanceSample"
                StartupObject = ""
            >
                <Config
                    Name = "Debug"
                    AllowUnsafeBlocks = "false"
                    BaseAddress = "285212672"
                    CheckForOverflowUnderflow = "false"
                    ConfigurationOverrideFile = ""
                    DefineConstants = "DEBUG;TRACE"
                    DocumentationFile = ""
                    DebugSymbols = "true"
                    FileAlignment = "4096"
                    IncrementalBuild = "true"
                    Optimize = "false"
                    OutputPath = "bin\"
                    RegisterForComInterop = "false"
                    RemoveIntegerChecks = "false"
                    TreatWarningsAsErrors = "false"
                    WarningLevel = "4"
                />
                <Config
                    Name = "Release"
                    AllowUnsafeBlocks = "false"
                    BaseAddress = "285212672"
                    CheckForOverflowUnderflow = "false"
                    ConfigurationOverrideFile = ""
                    DefineConstants = "TRACE"
                    DocumentationFile = ""
                    DebugSymbols = "false"
                    FileAlignment = "4096"
                    IncrementalBuild = "false"
                    Optimize = "true"
                    OutputPath = "bin\"
                    RegisterForComInterop = "false"
                    RemoveIntegerChecks = "false"
                    TreatWarningsAsErrors = "false"
                    WarningLevel = "4"
                />
            </Settings>
            <References>
                <Reference
                    Name = "System"
                    AssemblyName = "System"
                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
                />
                <Reference
                    Name = "System.Drawing"
                    AssemblyName = "System.Drawing"
                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Drawing.dll"
                />
                <Reference
                    Name = "System.Data"
                    AssemblyName = "System.Data"
                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
                />
                <Reference
                    Name = "System.Web"
                    AssemblyName = "System.Web"
                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Web.dll"
                />
                <Reference
                    Name = "System.XML"
                    AssemblyName = "System.Xml"
                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
                />
            </References>
        </Build>
        <Files>
            <Include>
                <File
                    RelPath = "AdvancedPageInheritance.aspx"
                    SubType = "Form"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "AdvancedPageInheritance.aspx.cs"
                    DependentUpon = "AdvancedPageInheritance.aspx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "AdvancedPageInheritance.aspx.resx"
                    DependentUpon = "AdvancedPageInheritance.aspx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "AdvancedPageInheritanceBase.cs"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "AssemblyInfo.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "Default.aspx"
                    SubType = "Form"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "Default.aspx.cs"
                    DependentUpon = "Default.aspx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "Default.aspx.resx"
                    DependentUpon = "Default.aspx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "FooterControl.ascx"
                    SubType = "UserControl"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "FooterControl.ascx.cs"
                    DependentUpon = "FooterControl.ascx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "FooterControl.ascx.resx"
                    DependentUpon = "FooterControl.ascx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "Global.asax"
                    SubType = "Component"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "Global.asax.cs"
                    DependentUpon = "Global.asax"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "Global.asax.resx"
                    DependentUpon = "Global.asax.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "HeaderControl.ascx"
                    SubType = "UserControl"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "HeaderControl.ascx.cs"
                    DependentUpon = "HeaderControl.ascx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "HeaderControl.ascx.resx"
                    DependentUpon = "HeaderControl.ascx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "MenuControl.ascx"
                    SubType = "UserControl"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "MenuControl.ascx.cs"
                    DependentUpon = "MenuControl.ascx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "MenuControl.ascx.resx"
                    DependentUpon = "MenuControl.ascx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "PageBase.cs"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "PageInheritanceSample.vsdisco"
                    BuildAction = "None"
                />
                <File
                    RelPath = "SimplePageInheritance.aspx"
                    SubType = "Form"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "SimplePageInheritance.aspx.cs"
                    DependentUpon = "SimplePageInheritance.aspx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "SimplePageInheritance.aspx.resx"
                    DependentUpon = "SimplePageInheritance.aspx.cs"
                    BuildAction = "EmbeddedResource"
                />
                <File
                    RelPath = "SimplePageInheritanceBase.cs"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "Web.config"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "WebUserControl.aspx"
                    SubType = "Form"
                    BuildAction = "Content"
                />
                <File
                    RelPath = "WebUserControl.aspx.cs"
                    DependentUpon = "WebUserControl.aspx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "WebUserControl.aspx.resx"
                    DependentUpon = "WebUserControl.aspx.cs"
                    BuildAction = "EmbeddedResource"
                />
            </Include>
        </Files>
    </CSHARP>
</VisualStudioProject>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Peter Provost has been programming computers since he was 10 years old. Currently a C# and C++ junkie, he has been developing on the Windows platform since Windows 286.

Peter is a Software Design Engineer with Microsoft's patterns and practices team where he works on guidance for .NET developers.

Peter maintains an active weblog about technology, .NET and other interesting stuff at http://www.peterprovost.org

Comments and Discussions