C#中在内容页获取其模板页中的对象,变量,或者值
在模板页中的程序入口改成:protected void Page_Init(object sender, EventArgs e)
在内容页:
string s1 = ((HomeMaster)this.Master).s1;
//HomeMaster是模板页的类名,也就是模板页的文件名
or
MasterPage2 masterpage2 = (MasterPage2)this.Master;
MasterPage masterpage = (MasterPage)masterpage2.Master;
Literal literal = (Literal)(masterpage.FindControl("liter1"));
Literal literalDesc = (Literal)(masterpage.FindControl("Liter_desc"));
literal.Text="www.";
literalDesc.Text="www.yaxdj.com";
母页中不需要设置title,在子页中设置title=""即可。
母版页中不要设置title就可以了。
内容页:
MasterPage masterpage = (MasterPage)this.Master;
masterpage.Page.Title = companyInfo.guanJianCi() + "-" + companyInfo.companyName() + ":" + companyInfo.companyDianHua();
masterpage.Page.MetaDescription = "上海茂联网络科技有限公司";