页面生命周期 - 使用的FindControl来参一控过程中页面加载编程创建 [英] Page Lifecycle - Using FindControl to reference a control created programatically during page load

查看:124
本文介绍了页面生命周期 - 使用的FindControl来参一控过程中页面加载编程创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建我的窗体上某些文本框编程,我需要用的FindControl以后参考。

I'm creating some text boxes on my form programatically which I need to reference later using FindControl.

我已经把的FindControl指令在页面加载方法后,code创造他们,但得到一个错误:

I've put the FindControl instruction in the page load method after the code which creates them but get an error:

对象引用未设置到对象的实例。

我想这是因为文本框控件没有创建,直到后来在生命周期,因此无法从内部的Page_Load引用。

I assume this is because the textbox controls are not created until later in the lifecycle and therefore cannot be referenced from within Page_Load.

可有人提醒凡在我code-后面我需要放置的FindControl指令,以便它可以找到这些编程方式创建的文本框?

Can someone advise where in my code-behind I would need to place the FindControl instruction so that it can find these programatically created text boxes?

推荐答案

你把你的文本框控件的另一个控件中如面板或网格?如果是这样你需要递归搜索页面上的所有控件。

Did you put your textbox control inside of another control such as a panel or grid? If so you need to recursively search all the controls on the page.

下面是一个递归的FindControl实现的例子:递归Page.FindControl 。你可以找到许多其它例子通过谷歌搜索递归的FindControl。

Here is an example of a recursive FindControl implementation: Recursive Page.FindControl. You can find many other examples by googling "recursive findcontrol".

这篇关于页面生命周期 - 使用的FindControl来参一控过程中页面加载编程创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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