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:
.designer.cs
file are null
.HasControls
return false
.EnsureChildControls
do nothing.Controls
collection 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!
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 WebControl
in the same directory as the Control
that 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...
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" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With