如何使用反射在嵌套母版页中查找页面上的用户控件

发布于 2024-09-29 23:21:03 字数 1296 浏览 2 评论 0原文

我有一个 CommonMaster 页面,其中包含一个 ConfigurableReportsMaster 页面。然后我有一个 AutitLog.aspx 页面。现在,在该 .aspx 页面上我有多个用户控件。其中一些 UserControl 继承自 ISQLFilter 接口,但不是全部。

在 .aspx 上,在 RunReport 事件(当前成功触发)中,我手动调用每个 UserControl(位于 ISQLFilter 接口中)的名为 .GetWhereClause() 的方法。

this.ucsStateFilter.GetWhereClause(ref sbWhere);
this.ucsStatusFilter.GetWhereClause(ref sbWhere);
this.ucsActivityType.GetWhereClause(ref sbWhere);
this.ucsVendorFilter.GetWhereClause(ref sbWhere);
this.ucsProducerFilter.GetWhereClause(ref sbWhere);
this.ucsNameFilter.GetWhereClause(ref sbWhere);
this.ucsPolicyFilter.GetWhereClause(ref sbWhere);
this.ucsShowAddressInfo.GetWhereClause(ref sbWhere);

这非常有效,并且完全符合我的需要。不过,为了便于使用,我希望只调用一个方法,例如 GetAllWhereClauses() ,该方法将使用 Reflection 来查找所有 UserControls(继承 ISQLFilter 接口)。这听起来非常简单我已经多次使用反射。我假设我可以这样做:

Type t = typeof(AuditLog);
PropertyInfo[] pis = t.GetProperties();

但是用户控件不在那里。我可以在 QuickWatch 窗口中查看 this 并查看我的每个 UserControl。我已尝试从页面和更深层次循环访问每个 .Controls 集,并且我可以成功访问 CommonMaster 页面上的控件。但这对我没有帮助。

也许是我想太多了。如果有帮助的话,我可以获取所有 "<%@ Register ... %> 项目的列表吗?我怀疑我只是缺少一个演员或其他东西。

提前致谢, 凯文

I have a CommonMaster page that then contains a ConfigurableReportsMaster page. I then have an AutitLog.aspx page. Now, on that .aspx page I have multiple UserControls. Some of these UserControls are inheriting from an ISQLFilter interface, but not all.

While on the .aspx, in a RunReport event (that currently successfully fires) I am manually calling a method of each UserControl (that is in the ISQLFilter interface) called .GetWhereClause().

this.ucsStateFilter.GetWhereClause(ref sbWhere);
this.ucsStatusFilter.GetWhereClause(ref sbWhere);
this.ucsActivityType.GetWhereClause(ref sbWhere);
this.ucsVendorFilter.GetWhereClause(ref sbWhere);
this.ucsProducerFilter.GetWhereClause(ref sbWhere);
this.ucsNameFilter.GetWhereClause(ref sbWhere);
this.ucsPolicyFilter.GetWhereClause(ref sbWhere);
this.ucsShowAddressInfo.GetWhereClause(ref sbWhere);

This works great and does exactly what I need. I would like though, for ease of use, is to just call one method, say GetAllWhereClauses() that would use Reflection to find all of the UserControls (that inherit the ISQLFilter interface.) It sounds really simple and I have used reflection numerous times. I would assume I could have just done:

Type t = typeof(AuditLog);
PropertyInfo[] pis = t.GetProperties();

But the UserControls are not there. I can look at this in the QuickWatch window and see each of my UserControls. I have tried a looping through each of the .Controls sets from the Page and deeper and I can successfully get to controls that I have on the CommonMaster page. But that doesn't help me here.

Perhaps I am thinking too much about it. If it would help, can I just get a list of all of the "<%@ Register ... %> items? I suspect I am just missing one cast or something.

Thanks in advance,
Kevin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文