简体   繁体   English

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

[英]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.

相关问题 使用jQuery AJAX在控制代码隐藏而不是页面代码隐藏中调用ASP.NET函数 - Using jQuery AJAX to call ASP.NET function in control code-behind instead of page code-behind Asp.net 母版页通过后面的代码动态控制 - Asp.net Master Page control dynamically through code behind 如何在代码隐藏页面的控制下滚动ASP.NET页面? - How can I scroll an ASP.NET page under control of the code-behind page? ASP.Net:ClientID在用户控件的代码隐藏中不正确 - ASP.Net: ClientID not correct in code-behind of a user control 从代码隐藏中删除asp.net控件 - Remove an asp.net control from code-behind Asp.net 在代码隐藏中打开 DropDownList 控件 - Asp.net open DropDownList control in code-behind 从 Asp.Net 的代码隐藏控制灯箱(模态) - Control Lightbox (Modal) From Code-Behind Of Asp.Net ASP.Net Web 用户控制方法和事件在主机页面的代码隐藏中不可用 - ASP.Net Web User Control methods and events not available in code-behind of host page 在母版页代码中访问ASP.NET母版页DropDownList控件 - Access ASP.NET Master Page DropDownList Control in the Master Page's Code Behind 在来自母版页控件的内容页中的变量后面的asp.net代码上设置jQuery选择器 - Set jQuery selector on asp.net code behind variable in Content Page that comes from a Master Page control
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM