1.页面时一个master母版页的内容页!
2.在content 中添加了 用户自定义控件!“UserControl1,UserControl2,UserControl3……” 一系列
3.在代码页 用 foreach (Control c in this.Controls) 遍历控件集合
4.发现 controls 集合中只有一个空件:{ASP.masterpage_default_master}
为什么? 是哪里错了?另外用this.findcontrols("UserControl3"); 得到的确是null 控件明明是在页面中啊!补充: 页面中有个lblMessage 的控件 用findcontrols() 去找同样找不到!
2.在content 中添加了 用户自定义控件!“UserControl1,UserControl2,UserControl3……” 一系列
3.在代码页 用 foreach (Control c in this.Controls) 遍历控件集合
4.发现 controls 集合中只有一个空件:{ASP.masterpage_default_master}
为什么? 是哪里错了?另外用this.findcontrols("UserControl3"); 得到的确是null 控件明明是在页面中啊!补充: 页面中有个lblMessage 的控件 用findcontrols() 去找同样找不到!
ContentPlaceHolder holder2 = (ContentPlaceHolder)holder.FindControl("ContentPlaceHolder2");
TextBox txt = holder2.FindControl("TextBox1") as TextBox;
ContentPlaceHolder holder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)holder.FindControl("WebUserControl1");
Label lbl=uc.FindControl("Label1") as TextBox;
在这个用户空间的page_load里面找UserControl1控件 而不应该在母板页里面找 这些控件时属于
用户控件的子控件.所以你在母板页找到的controls其实是指的当前这个用户控件,非UserControl1...示例
((TextBox)this.FindControl("TextBox1")).Text = "213";