The Code:
ParentControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ParentControl.ascx.cs"
Inherits="ParentControl" %>
<%@ Register Src="~/ChildControl.ascx" TagPrefix="Prefix" TagName="ChildControlTag" %>
ParentControl.ascx.cs
public partial class ParentControl : UserControl
{
List<ASP.childcontrol_asxc> controlList = new List<ASP.childcontrol_asxc>();
... inside a public property setter ...
var control = new ASP.childcontrol_ascx(); // <ABC> what the heck is this reference?
controlList.Add(control);
...
}
ChildControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChildControl.ascx.cs"
Inherits="ChildControl" %>
<asp:Repeater ID="childRepeater" runat="server" EnableViewState="false"
ViewStateMode="Disabled">
ChildControl.ascx.cs
public partial class ChildControl : UserControl
{
...
protected void Page_Load(object sender, EventArgs e)
{
childRepeater.DataSource = xyz; // <XYZ> crashes if I don't use the weird reference
}
}
The Problem:
I don't understand what the reference comment marked with <ABC>
is all about. That's not the class I defined... but Intellisense doesn't complain. If I press F12
on it, it takes me to the <%@ Control ... %>
tag at the top of ChildControl.ascx instead of the control definition in ChildControl.ascx.cs.
I don't understand what this other version of the control is, why it's in the ASP namespace, or what the implications of using it instead of the control directly are. Worse, this compiles fine on my local workstation, but throws a compiler error on the TFS server we use for CI.
The Question:
Does anyone know the name for this method of using/referencing the custom User Controls, and/or have links/information I can look at to get a better handle on what this is and what the implications are? I've been unable to find anything useful via Google. While a fix/workaround would be great to have - I would still like to be able to research the technique.
Explorations:
I've tried replacing the usages with the actual class name, instead of the weird ASP.class_ascx
references... it compiles fine if I do this, but unfortunately it fails at runtime. It seems like the other reference changes how it interacts with the asp.NET lifecycle - server controls defined in the aspx of the child control are null in the Page_Load()
of the child control (marked <XYZ>
). Under the weird ASP.control_ascx
reference approach, the repeaters are properly defined when it hits the Page_Load()
of the child controls, but I don't understand why.
Miscellaneous:
The project is using the Roslyn compiler on my local workstation, via the DotNetCompilerPlatform NuGet package but I believe its just using the VS/TFS 2015 built in compiler on the CI server. This might explain why TFS throws compiler errors - it tells me The type or namespace name 'usercontrol_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)
. I'm looking at configuring TFS to use the compiler from the NuGet package which will then hopefully compile - but this is still weird and I'd like to understand it.