问题描述
在 asp.net web 表单中 - 我在 web 表单中动态添加了一组单选按钮,并在我尝试查找时单击提交按钮使用 find.control(id) 使用其 id 的单选按钮按钮,它返回 null.有人可以帮助我是 asp.net 的新手吗?
RadioButton myControl1 = (RadioButton)Page.FindControl("r11");
两个原因.
动态添加控件时,必须在页面回发时重新添加(在Page_Init中是个好地方).请参阅如何持久化动态控件
另一个是 Page.FindControl() 只向下一级,你需要递归地向下搜索列表.请参阅在 ASP.NET 中查找控件的更好方法>
In asp.net web form-I have added group of radio button dynamically in web form and on clicking submit button when i try to the find the radio button button with its id using find.control(id), it returns null. Can some body help me am new to asp.net?
RadioButton myControl1 = (RadioButton)Page.FindControl("r11");
Two reasons.
When you add controls dynamically, you must re-add them when the page posts back (In Page_Init is a good place). See How to persist a dynamic control
The other is that Page.FindControl() only goes one level down, you need to recursively search down the list. See Better way to find control in ASP.NET
这篇关于Page.FindControl() 搜索动态控件时返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!