Inside my page, I have the following:
<aspe:UpdatePanel runat="server" ID="updatePanel">
<ContentTemplate>
<local:KeywordSelector runat="server" ID="ksKeywords" />
</ContentTemplate>
</aspe:UpdatePanel>
The KeywordSelector control is a control I define in the same assembly and local is mapped to its namespace.
The control is made up of several other controls and is defined as such:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="KeywordSelector.ascx.cs"
Inherits="Keywords.KeywordSelector" %>
and has quite a few server controls of its own, all defined as members in the .designer.cs file.
However, during no part of the control’s lifecycle does it have any child control objects nor does it produce HTML:
- All of the members defined in the
.designer.csfile arenull. - Calls to
HasControlsreturnfalse. - Calls to
EnsureChildControlsdo nothing. - The
Controlscollection is empty.
Removing the UpdatePanel did no good. I tried to reproduce it in a clean page with a new UserControl and the same thing happens.
I am using ASP.NET over .NET Framework 3.5 SP1 with the integrated web server.
What am I missing here?
Update #1: Following Rob’s comment, I looked into OnInit and found that the UserControl does not detect that it has any child controls. Moreover, CreateControlCollection is never called!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Well, I’ve found the problem(s):
-
User Controls, as opposed to Custom Controls must be registered one-by-one in the web.config file. Do this:
<add tagPrefix="local" tagName="KeywordSelector" src="~/KeywordSelector.ascx" />instead of:
<add tagPrefix="local" namespace="Keywords" assembly="Keywords" /> -
You should never place a
WebControlin the same directory as theControlthat is using it. This is downright silly. Read about it here.
Thanks for the help. Now if only I could mark my own answer as the answer…
Method 2
In my case the reason was the Resharper 7.1 added incorrect @Register directive at the top of aspx – instead of this desired row:
<%@ Register Src="~/Controls/Hello/Hello.ascx" TagName="Hello" TagPrefix="p" %>
i got wrong one:
<%@ Register TagPrefix="p" Namespace="MyNamespace.WebApp.Controls" Assembly="MyApp.Web" %>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0