Page.FindControl() returns null when searching for dynamic control(Page.FindControl() 搜索动态控件时返回 null)
问题描述
在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Page.FindControl() 搜索动态控件时返回 null


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01