在asp.net网页表单中 - 我已经在网络表单中动态添加了单选按钮组,并在我尝试查找时单击提交按钮 单选按钮按钮,其id使用find.control(id),它返回null。有些人可以帮助我成为asp.net的新手吗?
RadioButton myControl1 = (RadioButton)Page.FindControl("r11");
答案 0 :(得分:4)
有两个原因。
当您动态添加控件时,必须在页面回发时重新添加它们(在Page_Init中是个好地方)。见How to persist a dynamic control
另一个是Page.FindControl()只降低一级,你需要递归搜索列表。见Better way to find control in ASP.NET