[英]Render a ASP.NET control in the master page code-behind
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 . 我在母版页中使用Substitution控件,并且想要在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 ks
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? 因此,您想从背后的MasterPage代码中呈现用户控件,并将其添加到母版页中的Substitution中吗? 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: 假设您使用的是VB并且我了解您的问题,请在您的MasterPage后台代码中尝试以下操作:
Dim someControl As MyControl = CType((New Page()).LoadControl("~/Path/To/MyControl.ascx"), MyControl)
mySubstitution.Controls.Add(someControl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.