在母版页代码隐藏中呈现 ASP.NET 控件

发布于 2024-08-02 12:07:06 字数 165 浏览 4 评论 0原文

我在我的母版页中使用 Substitution 控件,并且我想在 Substitution 中呈现用户控件内容(与我的网站的登录区域相关)。 似乎我必须有所请求页面的引用,以便它可以呈现控件。但我需要在母版页本身中呈现控件,因为它在我的网站中的多个页面之间共享。实现这一目标的指导方针是什么?

塔克斯

I'm using a Substitution control in my master page, and I want to render a user control content (related to the login area of my website) in the Substitution .
Seems like I must have a reference for the requested page so that it could render the control. But I need to render the control in the master page itself, as it's shared across multiple pages in my website. What are the guidelines to achieve that?

Tks

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

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

发布评论

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

评论(1

意中人 2024-08-09 12:07:06

您想从 MasterPage 代码隐藏中呈现用户控件,并将其添加到母版页中的 Substitution 中吗?为什么需要对使用母版的页面的引用?

假设您使用 VB 并且我理解您的问题,请在您的 MasterPage 代码隐藏中尝试以下操作:

Dim someControl As MyControl = CType((New Page()).LoadControl("~/Path/To/MyControl.ascx"), MyControl)
mySubstitution.Controls.Add(someControl)

So you want to render a user control from your MasterPage code-behind, and add it to a Substitution that's also in the master page? Why do you need a reference to the page that's using the master?

Assuming your using VB and that I understand your question, try this in your MasterPage code-behind:

Dim someControl As MyControl = CType((New Page()).LoadControl("~/Path/To/MyControl.ascx"), MyControl)
mySubstitution.Controls.Add(someControl)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文