Page.FindControl()用于动态控制搜索时返回null [英] Page.FindControl() returns null when searching for dynamic control
问题描述
在asp.net web表单,我已经在动态Web表单并点击提交按钮,当我尝试查找添加的单选按钮组
使用find.control(ID),它的ID单选按钮按钮,则返回null。一些身体可以帮助我是新来的ASP.NET?
单选myControl1 =(单选)Page.FindControl(R11);
有两个原因。
当您添加控件动态,必须重新添加他们当页面回(在Page_Init是个好地方)。见如何坚持动态控制
另外是Page.FindControl()只去下一层,你需要递归搜索在列表中向下。请参见更好的方法来查找ASP.NET 控制p>
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!