Note that there are some explanatory texts on larger screens.

plurals
  1. POUser controls called from child pages do not appear on master page
    text
    copied!<p>I have a custom user control in ASP.net:</p> <p>MenuButton.ascx:</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="~/MenuButton.ascx.cs" Inherits="MenuButton" ClassName="MenuButton" %&gt; &lt;li&gt;&lt;a href="&lt;%= Link %&gt;"&gt;&lt;span&gt;&lt;%= Text %&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>MenuButton.ascx.cs:</p> <pre><code>using System; public partial class MenuButton : System.Web.UI.UserControl { public String Link = "test.html"; public String Text = "TEST"; protected void Page_Load(object sender, EventArgs e) { } } </code></pre> <p>MasterPage.master has this:</p> <pre><code>&lt;%@ Reference Control="~/MenuButton.ascx" %&gt; &lt;%@ Register Src="~/MenuButton.ascx" TagName="Menu" TagPrefix="button" %&gt; &lt;ul runat="server" id="Menu"&gt;&lt;/ul&gt; </code></pre> <p>MasterPage.master.cs</p> <pre><code>public List&lt;MenuButton&gt; Menus = new List&lt;MenuButton&gt;(); protected void Page_Load(object sender, EventArgs e) { foreach (var control in Menus) { Menu.Controls.Add(control); } } </code></pre> <p>Default.aspx</p> <pre><code>Master.Menus.Add( new MenuButton { Text = "Test1", Link = "test1.html" }); </code></pre> <p>It compiles OK, even with the debugger it does what it should do but they just don't appear on my page. Am I missing something here?</p> <p>Thanks.</p> <hr> <p>Edit 1:</p> <p>I tried to override OnInit on my master page:</p> <pre><code>protected override void OnInit(EventArgs e) { base.OnInit(e); foreach (var control in SousMenus) { SousMenu.Controls.Add(control); } } </code></pre> <p>It didn't work also.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload