Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么可以';asp.net是否找到我的自定义网络控件?_Asp.net_Null_Custom Controls_Registration_Web Controls - Fatal编程技术网

为什么可以';asp.net是否找到我的自定义网络控件?

为什么可以';asp.net是否找到我的自定义网络控件?,asp.net,null,custom-controls,registration,web-controls,Asp.net,Null,Custom Controls,Registration,Web Controls,我有一个自定义控件,一旦它知道其他控件的关系,它就会做一些奇特的事情。下面是我如何把这些东西连接起来的,如果你知道更好的方法,我愿意接受建议 首先我创建了一些接口,然后是管理关系的控件 public interface IRegisterSelf { string ParentId { get; set; } string CustomControlId { get; set; } void RegisterToControl(ICustomControl control

我有一个自定义控件,一旦它知道其他控件的关系,它就会做一些奇特的事情。下面是我如何把这些东西连接起来的,如果你知道更好的方法,我愿意接受建议

首先我创建了一些接口,然后是管理关系的控件

public interface IRegisterSelf
{
    string ParentId { get; set; }
    string CustomControlId { get; set; }
    void RegisterToControl(ICustomControl controller);
}

public interface ICustomControl
{
    void Register(IRegisterSelf child, IRegisterSelf parent);
}

public class CustomControl : WebControl, ICustomControl
{
    public List<KeyValuePair<IRegisterSelf, IRegisterSelf>> _relationShips 
        = new List<KeyValuePair<IRegisterSelf, IRegisterSelf>>();

    public void Register(IRegisterSelf child, IRegisterSelf parent)
    {
        _relationShips.Add(new KeyValuePair<IRegisterSelf, IRegisterSelf>(parent, child));
    }
}
然后使用标记定义所有这些关系:

<c:CustomControl ID="myControl" runat="server" />

<c:CustomDDL ID="box1" CustomControlId="myControl" runat="server">
    <asp:ListItem Text="_value1" Value="Value 1" />
    <asp:ListItem Text="_value2" Value="Value 2" />
    <asp:ListItem Text="_value3" Value="Value 3" />
</c:CustomDDL>

<c:CustomDDL ID="box2" ParentId="box1" CustomControlId="myControl" runat="server">
    <asp:ListItem Text="_value1" Value="Value 1" />
    <asp:ListItem Text="_value2" Value="Value 2" />
    <asp:ListItem Text="_value3" Value="Value 3" />
</c:CustomDDL>


问题是,在CustomDDL的CustomControlId属性中,我无法注册控制器,因为asp.net说它找不到它。FindControl始终返回null。为什么?我设置了ID,并将runat属性设置为server。我甚至可以在生成的HTML中看到它。任何帮助都将不胜感激。

FindControl不会在页面上递归查找控件。有关修复方法,请参阅。

FindControl不会在页面上递归查找控件。有关修复方法,请参阅。

请向我们展示您使用FindControl的位置以及您控制的父亲。请向我们展示您使用FindControl的位置以及您控制的父亲。
<c:CustomControl ID="myControl" runat="server" />

<c:CustomDDL ID="box1" CustomControlId="myControl" runat="server">
    <asp:ListItem Text="_value1" Value="Value 1" />
    <asp:ListItem Text="_value2" Value="Value 2" />
    <asp:ListItem Text="_value3" Value="Value 3" />
</c:CustomDDL>

<c:CustomDDL ID="box2" ParentId="box1" CustomControlId="myControl" runat="server">
    <asp:ListItem Text="_value1" Value="Value 1" />
    <asp:ListItem Text="_value2" Value="Value 2" />
    <asp:ListItem Text="_value3" Value="Value 3" />
</c:CustomDDL>