我要创建我的窗体上某些文本框编程,我需要用的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".