查找页面上的所有控件

时间:2021-04-26 15:51:23

If I start with

如果我开始

Page.Controls

Then recursively call all the children control.Controls, will the guarantee that I find all the controls that exist on a given page. Are there any time that orphaned controls can exist, or any other controls that will not show up when iterating through the page's controls in this way?

然后递归调用所有子控件。控件,将保证我找到给定页面上存在的所有控件。是否有任何时候可以存在孤立控件,或者以这种方式迭代页面控件时不会显示的任何其他控件?

Even if this is correct is there a better way of finding all of a page's controls?

即使这是正确的,有更好的方法来查找页面的所有控件吗?

3 个解决方案

#1


It will find all the controls that exist when you ask. There's nothing to say that more controls won't be added later, after DataBinding, for instance.

当你提问时,它会找到所有存在的控件。没有什么可说的,例如,在DataBinding之后,以后不会添加更多的控件。

Maybe you want to check in the OnPreRenderComplete method?

也许你想检查一下OnPreRenderComplete方法?

#2


Obviously, this will give you controls with runat=server specified. It won't give plain old HTML controls.

显然,这将为您提供指定runat = server的控件。它不会提供普通的旧HTML控件。

#3


I use ControlFinder helper for access to all my children controls. Get it and adapt to your code.

我使用ControlFinder帮助程序访问我所有的子控件。获取它并适应您的代码。

#1


It will find all the controls that exist when you ask. There's nothing to say that more controls won't be added later, after DataBinding, for instance.

当你提问时,它会找到所有存在的控件。没有什么可说的,例如,在DataBinding之后,以后不会添加更多的控件。

Maybe you want to check in the OnPreRenderComplete method?

也许你想检查一下OnPreRenderComplete方法?

#2


Obviously, this will give you controls with runat=server specified. It won't give plain old HTML controls.

显然,这将为您提供指定runat = server的控件。它不会提供普通的旧HTML控件。

#3


I use ControlFinder helper for access to all my children controls. Get it and adapt to your code.

我使用ControlFinder帮助程序访问我所有的子控件。获取它并适应您的代码。