代码:
父控件.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ParentControl.ascx.cs"
Inherits="ParentControl" %>
<%@ Register Src="~/ChildControl.ascx" TagPrefix="Prefix" TagName="ChildControlTag" %>
父控件.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);
...
}
子控件.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
}
}
问题:
我不明白标有
<ABC>
的引用评论是什么是所有关于。那不是我定义的类……但 Intellisense 不会提示。如果我按 F12
在它上面,它带我到<%@ Control ... %>
标记位于 ChildControl.ascx 顶部,而不是 ChildControl.ascx.cs 中的控件定义。我不明白这个控件的其他版本是什么,为什么它在 ASP 命名空间中,或者直接使用它而不是控件的含义是什么。更糟糕的是,这在我的本地工作站上编译得很好,但在我们用于 CI 的 TFS 服务器上引发了编译器错误。
问题:
有谁知道这种使用/引用自定义用户控件的方法的名称,和/或有我可以查看的链接/信息以更好地处理这是什么以及含义是什么?我一直无法通过谷歌找到任何有用的东西。虽然修复/解决方法会很棒 - 我仍然希望能够研究该技术。
探索:
我尝试用实际的类名替换用法,而不是奇怪的
ASP.class_ascx
引用...如果我这样做,它编译得很好,但不幸的是它在运行时失败。似乎其他引用更改了它与 asp.NET 生命周期的交互方式 - 在子控件的 aspx 中定义的服务器控件在 Page_Load()
中为空。子控件(标记为 <XYZ>
)。怪下ASP.control_ascx
引用方法,中继器在到达 Page_Load()
时被正确定义的 child 控制,但我不明白为什么。杂项:
该项目在我的本地工作站上使用 Roslyn 编译器,通过 DotNetCompilerPlatform NuGet package但我相信它只是在 CI 服务器上使用 VS/TFS 2015 内置编译器。这可以解释为什么 TFS 会抛出编译器错误 - 它告诉我
The type or namespace name 'usercontrol_ascx' does not exist in the namespace 'ASP' (are you missing an assembly reference?)
.我正在考虑将 TFS 配置为使用 NuGet 包中的编译器,然后希望它可以编译 - 但这仍然很奇怪,我想理解它。
最佳答案
这是 ASPX 文件编译到的类。它继承您的类并添加呈现您的 ASPX 内容的代码。
关于c# - 我需要帮助确定一种编程技术,以便我可以研究和修复它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48550547/