我可以知道母版页的 ContentPlaceHolder 中有哪个页面吗?

发布于 2024-09-18 15:37:20 字数 251 浏览 4 评论 0原文

我遇到的所有 Google 发现都告诉我如何使用 FindControl 从内容页面本身访问母版上的控件。

然而,我想做的却恰恰相反。 从母版页中,我想引用 ContentPlaceHolder 中的任何子页面。

你为什么问。 我希望母版页知道哪个选项卡应处于活动状态,具体取决于占位符中当前的内容页面。 这可以让我避免让每个页面都引用母版页并允许他们更改活动选项卡;这应该是母版页的工作(如果有办法知道它包含的是谁)。

谢谢。请不要咆哮。

All the Google finds I ran into tell me how to use FindControl to access a control on the master from the content page itself.

However, what I'm trying to do is the opposite.
From the master page, I want to reference whichever child page is in the ContentPlaceHolder.

Why you ask.
I want the master page to know which tab should be active depending on the content Page currently in the placeholder.
This lets me avoid having each page to reference the master page and allow them to change the active tab; that should be the master page's job (if there's a way it can know whom it's enclosing).

Thanks. No rants please.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2024-09-25 15:37:20

如果您希望获取正在执行的页面类的实例,您可以从当前的 HTTP 上下文中检索它:

var page = HttpContext.Current.CurrentHandler as Page;

从那里,您可以导航页面的控制树,调用 FindControl() 等。不过,请谨慎对待页面生命周期,因为母版页事件往往会在其对应的页面事件之前触发。

If you are looking to get the instance of the executing page class, you can retrieve it from the current HTTP context:

var page = HttpContext.Current.CurrentHandler as Page;

From there, you can navigate the page's control tree, call FindControl(), and so on. Be cautious about page lifecycle, though, as master page events tend to fire before their page event counterparts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文