<!--
版模页
-->
<% @ Master Language = " C# " AutoEventWireup = " true " Inherits = " DuwControls.DuwDefaultMasterPage " %>
<! 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 " >
< asp:contentplaceholder id = " CHead " runat = " server " >
</ asp:contentplaceholder >
</ head >
< body >
< form id = " form1 " runat = " server " >
< asp:ContentPlaceHolder ID = " ScriptMan " runat = " server " >
ScriptMain
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CTop " runat = " server " >
CTop
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CLeft " runat = " server " >
CLeft
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CMain " runat = " server " >
CMain
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CRight " runat = " server " >
CRight
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CFoot " runat = " server " >
CFoot
</ asp:ContentPlaceHolder >
</ form >
</ body >
</ html >
ContentPlaceHolder 为模版部分的占用位置
// 模版页后台,继承自系统 System.Web.UI.MasterPage
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;
namespace DuwControls
... {
public class DuwDefaultMasterPage : MasterPage
...{
private ContentPlaceHolder _CHead;
private ContentPlaceHolder _CTop;
private ContentPlaceHolder _CLeft;
private ContentPlaceHolder _CMain;
private ContentPlaceHolder _CRight;
private ContentPlaceHolder _CFoot;
private ContentPlaceHolder _ScriptMan;
public ContentPlaceHolder CHead ...{ get ...{ return _CHead; } }
public ContentPlaceHolder CTop ...{ get ...{ return _CTop; } }
public ContentPlaceHolder CLeft ...{ get ...{ return _CLeft; } }
public ContentPlaceHolder CMain ...{ get ...{ return _CMain; } }
public ContentPlaceHolder CRight ...{ get ...{ return _CRight; } }
public ContentPlaceHolder CFoot ...{ get ...{ return _CFoot; } }
public ContentPlaceHolder ScriptMan ...{ get ...{ return _ScriptMan; } }
protected override void OnInit(EventArgs e)
...{
foreach (Control ctrl in this.Controls)
...{
if (ctrl is System.Web.UI.HtmlControls.HtmlHead)//模版Head头部部分
...{
foreach (Control ctl in ctrl.Controls)
...{
if (ctl is ContentPlaceHolder)
...{
_CHead = ctl as ContentPlaceHolder;
}
}
}
else if (ctrl is System.Web.UI.HtmlControls.HtmlForm)//模版Form主体部分
...{
foreach (Control ctl in ctrl.Controls)
...{
if (ctl is ContentPlaceHolder)
...{
switch (ctl.ID)
...{
case "CTop":
_CTop = ctl as ContentPlaceHolder;
break;
case "CLeft":
_CLeft = ctl as ContentPlaceHolder;
break;
case "CMain":
_CMain = ctl as ContentPlaceHolder;
break;
case "CRight":
_CRight = ctl as ContentPlaceHolder;
break;
case "CFoot":
_CFoot = ctl as ContentPlaceHolder;
break;
case "ScriptMan":
_ScriptMan = ctl as ContentPlaceHolder;
break;
default:
break;
}
}
}
}
}
base.OnInit(e);
}
}
}
// 页面.cs运用部分
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using DuwCompontents;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
namespace DuwControls
... {
public class DuwPage : Page
...{
属性#region 属性
public string SkinType
...{
get ...{ return _SkinType; }
set ...{ _SkinType = value; }
}
public int BoardID ...{ get ...{ return _BoardID; } set ...{ _BoardID = value; } }
#endregion
事件#region 事件
protected override void OnPreInit(EventArgs e)
...{
_SkinType = "wow";//修改页面的SkinType属性
this.MasterPageFile = "/Themes/wow/Default.master"; //修改模版页的原引用路径/Themes/Default/Default.master
DuwDefaultMasterPage dp = this.Master as DuwDefaultMasterPage;//取得页面的模版
dp.CTop //为模板中的CTop占位部分
base.OnPreInit(e);
}
}
}
// aspx页面部分
<% @ Page Language = " C# " MasterPageFile = " ~/Themes/Default/Default.master " ValidateRequest = " false "
Inherits = " DuwControls.DuwPage " SkinType = " default " %>
< asp:Content ID = " Content1 " ContentPlaceHolderID = " CHead " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content2 " ContentPlaceHolderID = " ScriptMan " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content3 " ContentPlaceHolderID = " CTop " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content4 " ContentPlaceHolderID = " CLeft " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content5 " ContentPlaceHolderID = " CMain " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content6 " ContentPlaceHolderID = " CRight " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content7 " ContentPlaceHolderID = " CFoot " Runat = " Server " >
</ asp:Content >
<% @ Master Language = " C# " AutoEventWireup = " true " Inherits = " DuwControls.DuwDefaultMasterPage " %>
<! 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 " >
< asp:contentplaceholder id = " CHead " runat = " server " >
</ asp:contentplaceholder >
</ head >
< body >
< form id = " form1 " runat = " server " >
< asp:ContentPlaceHolder ID = " ScriptMan " runat = " server " >
ScriptMain
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CTop " runat = " server " >
CTop
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CLeft " runat = " server " >
CLeft
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CMain " runat = " server " >
CMain
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CRight " runat = " server " >
CRight
</ asp:ContentPlaceHolder >
< asp:ContentPlaceHolder ID = " CFoot " runat = " server " >
CFoot
</ asp:ContentPlaceHolder >
</ form >
</ body >
</ html >
ContentPlaceHolder 为模版部分的占用位置
// 模版页后台,继承自系统 System.Web.UI.MasterPage
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;
namespace DuwControls
... {
public class DuwDefaultMasterPage : MasterPage
...{
private ContentPlaceHolder _CHead;
private ContentPlaceHolder _CTop;
private ContentPlaceHolder _CLeft;
private ContentPlaceHolder _CMain;
private ContentPlaceHolder _CRight;
private ContentPlaceHolder _CFoot;
private ContentPlaceHolder _ScriptMan;
public ContentPlaceHolder CHead ...{ get ...{ return _CHead; } }
public ContentPlaceHolder CTop ...{ get ...{ return _CTop; } }
public ContentPlaceHolder CLeft ...{ get ...{ return _CLeft; } }
public ContentPlaceHolder CMain ...{ get ...{ return _CMain; } }
public ContentPlaceHolder CRight ...{ get ...{ return _CRight; } }
public ContentPlaceHolder CFoot ...{ get ...{ return _CFoot; } }
public ContentPlaceHolder ScriptMan ...{ get ...{ return _ScriptMan; } }
protected override void OnInit(EventArgs e)
...{
foreach (Control ctrl in this.Controls)
...{
if (ctrl is System.Web.UI.HtmlControls.HtmlHead)//模版Head头部部分
...{
foreach (Control ctl in ctrl.Controls)
...{
if (ctl is ContentPlaceHolder)
...{
_CHead = ctl as ContentPlaceHolder;
}
}
}
else if (ctrl is System.Web.UI.HtmlControls.HtmlForm)//模版Form主体部分
...{
foreach (Control ctl in ctrl.Controls)
...{
if (ctl is ContentPlaceHolder)
...{
switch (ctl.ID)
...{
case "CTop":
_CTop = ctl as ContentPlaceHolder;
break;
case "CLeft":
_CLeft = ctl as ContentPlaceHolder;
break;
case "CMain":
_CMain = ctl as ContentPlaceHolder;
break;
case "CRight":
_CRight = ctl as ContentPlaceHolder;
break;
case "CFoot":
_CFoot = ctl as ContentPlaceHolder;
break;
case "ScriptMan":
_ScriptMan = ctl as ContentPlaceHolder;
break;
default:
break;
}
}
}
}
}
base.OnInit(e);
}
}
}
// 页面.cs运用部分
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using DuwCompontents;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
namespace DuwControls
... {
public class DuwPage : Page
...{
属性#region 属性
public string SkinType
...{
get ...{ return _SkinType; }
set ...{ _SkinType = value; }
}
public int BoardID ...{ get ...{ return _BoardID; } set ...{ _BoardID = value; } }
#endregion
事件#region 事件
protected override void OnPreInit(EventArgs e)
...{
_SkinType = "wow";//修改页面的SkinType属性
this.MasterPageFile = "/Themes/wow/Default.master"; //修改模版页的原引用路径/Themes/Default/Default.master
DuwDefaultMasterPage dp = this.Master as DuwDefaultMasterPage;//取得页面的模版
dp.CTop //为模板中的CTop占位部分
base.OnPreInit(e);
}
}
}
// aspx页面部分
<% @ Page Language = " C# " MasterPageFile = " ~/Themes/Default/Default.master " ValidateRequest = " false "
Inherits = " DuwControls.DuwPage " SkinType = " default " %>
< asp:Content ID = " Content1 " ContentPlaceHolderID = " CHead " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content2 " ContentPlaceHolderID = " ScriptMan " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content3 " ContentPlaceHolderID = " CTop " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content4 " ContentPlaceHolderID = " CLeft " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content5 " ContentPlaceHolderID = " CMain " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content6 " ContentPlaceHolderID = " CRight " Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content7 " ContentPlaceHolderID = " CFoot " Runat = " Server " >
</ asp:Content >