简体   繁体   English

在页面上查找所有控件

[英]Finding all Controls on a Page

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? 即使这是正确的,是否还有更好的方法来查找页面的所有控件?

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方法?

Obviously, this will give you controls with runat=server specified. 显然,这将为您提供指定runat = server的控件。 It won't give plain old HTML controls. 它不会提供简单的旧HTML控件。

I use ControlFinder helper for access to all my children controls. 我使用ControlFinder助手来访问我的所有子控件。 Get it and adapt to your code. 得到它并适应您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM