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


基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01