我该如何查找母版页里的内容页的所有checkbox控件呢
前台页面:
- HTML code
<td class="forumrowhighlight"> <div id="DIVcheck" runat="server"> </div></td>
后台生成checkbox语句
- C# code
DataSet ds = ActionBLL.GetAllList();foreach (DataRow dr in ds.Tables[0].Rows){ CheckBox ck = new CheckBox(); HtmlGenericControl div = new HtmlGenericControl("div"); DIVcheck.Controls.Add(div); ck.Text = dr["action_name"].ToString(); ck.ID = dr["action_id"].ToString(); div.Style.Value = "float:left;width:150px"; div.Controls.Add(ck);}ds.Dispose();后台获得checkbox语句
- C# code
foreach (Control ct in this.Master.Controls){ if (ct is CheckBox) { CheckBox ck = (CheckBox)ct; }}为什么获取不到呢 是什么原理啊。。。求指教。求例子
[解决办法]
你查找不到,应该是事件的顺序问题,你div.Controls.Add(ck);之后去查找应该是可以找到的