我有一个母版页A,另一个是嵌套A的母板页B(母版页B以A为母板页),但是我在B的内容也这样为什么不能找到母版页B的控件呢?
如下,内容页:
protected void Page_LoadComplete(object sender, EventArgs e)
    {        PreYearList = ((DropDownList)Master.FindControl("PreYearList"));//PreYearList为空,findcontrol的ID没有错的
}
是不是与嵌套母版页有关呢??

解决方案 »

  1.   

    PreYearList = ((DropDownList)Master.FindControl("PreYearList"));
    ------------------------------------------------------------------
    你这个Master就是母版页B的ID吗?如果不是,那当然是错的。你换成:
    PreYearList = ((DropDownList)this.FindControl("PreYearList"));试试。
      

  2.   

    PreYearList = ((DropDownList)Master.FindControl("PreYearList"));这段代码是在B的内容页中的~~~PreYearList是在母板页B中哦
      

  3.   

    通过this.Master获取直系Master,让后this.Master.Master可以获取父Master
    Master.Master.FindControl("")
      

  4.   

    呃~~但是我的PreYearList是在B上的,内容页是B的内容页。。
      

  5.   

    我在页B设置这样:
        public DropDownList _PreYearList
        {
            get
            {
                return PreYearList;
            }
        }然后在内容页就可以获取到: Year=Master._PreYearList.SelectedValue;//这样就可以~~~所以应该没有获取错层。。请指教!~~