在内容页里访问模板页控件,可用FindControl方法,例如:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Title = ConfigurationManager.AppSettings["comName"].ToString();
Master.FindControl("pMenu").ID = "index";
bindData();
}
}
判断控件是否存在可有效降低程序异常,例如:
if(Master.FindControl("pMenu") != null)
{
Master.FindControl("pMenu").ID = "index";
}