1. 在整个站点中应用母版页
<configuration> <system.web> <pages masterPageFile="~/Site.master" /> </system.web> </configuration>
2.动态应用母版页
void Page_PreInit (Object sender, EventArgs e) { Page.MasterPageFile = "~/Site.master"; }
3.操作模板页中的控件(两种方式:强类型与弱类型)
代码
强类型:
<asp:Label ID="Title" RunAt="server" />
.
.
.
<script language="C#" runat="server">
public string TitleText
{
get { return Title.Text; }
set { Title.Text = value; }
}
</script>
Master.TitleText = "Orders";
弱类型:
<asp:Label ID="Title" RunAt="server" />
((Label) Master.FindControl ("Title")).Text = "Orders";