Page.FindControl()用于动态控制搜索时返回null [英] Page.FindControl() returns null when searching for dynamic control

查看:239
本文介绍了Page.FindControl()用于动态控制搜索时返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net web表单,我已经在动态Web表单并点击提交按钮,当我尝试查找添加的单选按钮组
 使用find.control(ID),它的ID单选按钮按钮,则返回null。一些身体可以帮助我是新来的ASP.NET?

 单选myControl1 =(单选)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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆