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
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
