在 asp.net web 表单中-我在 web 表单中动态添加了一组单选按钮,并在我尝试查找时单击提交按钮 使用 find.control(id) 使用其 id 的单选按钮按钮,它返回 null。有人可以帮助我是 asp.net 的新手吗?
RadioButton myControl1 = (RadioButton)Page.FindControl("r11");
最佳答案
两个原因。
当您动态添加控件时,您必须在页面回发时重新添加它们(在 Page_Init 中是个好地方)。参见 How to persist a dynamic control
另一个是Page.FindControl()只向下一层,你需要递归地向下搜索列表。参见 Better way to find control in ASP.NET
关于asp.net - Page.FindControl() 在搜索动态控件时返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21663763/