Code
// About ASP. NET Dynamic Loading master page
// First create a master page Master. Master
/*
<% @ Master language = "C #" autoeventwireup = "true" codefile = "Master. Master. cs" inherits = "master" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns =" Http://www.w3.org/1999/xhtml ">
<Head runat = "server">
<Title> </title>
<Asp: contentplaceholder id = "head" runat = "server">
</ASP: contentplaceholder>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Span> master is using... </span>
<Asp: contentplaceholder id = "contentplaceholder1" runat = "server">
</ASP: contentplaceholder>
</Div>
</Form>
</Body>
</Html>
*/
// Create a content page and remove all HTML
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default2.aspx. CS " Inherits = " Default2 " %>
< ASP: Content runat = " Server " ID = " CT " Contentplaceholderid = " Contentplaceholder1 " >
< ASP: Label runat = " Server " ID = " Dd " > This Is A Test !! </ ASP: Label >
</ ASP: Content >
// Create a basic page
/// <Summary>
/// Basepage Summary
/// </Summary>
Public Class Basepage: system. Web. UI. Page
{
Public Basepage ()
{
//
// Todo: add the constructor logic here
//
This . Preinit + = New Eventhandler (basepage_preinit );
}
// The loading of the motherboard page is in the preinit event.
Void Basepage_preinit ( Object Sender, eventargs E)
{
Masterpagefile = " ~ /Master. Master " ;
}
}
// Finally, inherit the base class from the class on the Content Page.
Public Partial Class Default2: basepage
{
Protected Void Page_load ( Object Sender, eventargs E)
{
}
}