母版页 MasterPage

母版页是一个扩展名为.master的ASP.NET文件,主要是为了应用程序创建统一的用户功能界面和样式。

ContentPlaceHolder控件只能在母版页中使用,在平常的web页面使用,会发生解析器错误。

内容页中可以有多个Content服务器控件,但内容页里的Content控件的ContentPlaceHolderID必须与
ContentPlaceHolder控件的ID属性相同。

每个页面中vs会自动加入Content控件,它会自动覆盖母版页的ContentPlaceHolder里的内容,如果
需要展示ContentPlaceHolder控件的内容,不能再内容页加Content控件。

在内容页的Page_PreInit事件可以设置母版页的加载。
代码为
protected void Page_PreInit(object sender, EventArgs e)
{
Page.MasterPageFile = "MyMaster2.master";
}

猜你喜欢

转载自www.cnblogs.com/miss-bug/p/9132790.html