我有一个复合控件,它将一个 TextBox 和一个 Label 控件添加到它的 Controls 集合中。当我尝试将标签的 AssociatedControlID 设置为文本框的 ClientID 时,我收到此错误
Unable to find control with id
'ctl00_MainContentPlaceholder_MatrixSetControl_mec50_tb'
that is associated with the Label 'lb'.
好的,有一点背景。我得到了这个主复合控件,它动态地将许多“元素”添加到它的控件集合中。其中一个元素恰好是这个“MatrixTextBox”,它是由一个文本框和一个标签组成的控件。
我将 Label 和 TextBox 作为受保护的类变量,并在 CreateChildControls 中初始化它们:
ElementTextBox = new TextBox();
ElementTextBox.ID = "tb";
Controls.Add(ElementTextBox);
ElementLabel = new Label();
ElementLabel.ID = "lb";
Controls.Add(ElementLabel);
我尝试设置
ElementLabel.AssociatedControlID = ElementTextBox.ClientID;
在将控件添加到 Controls 集合之后,甚至在 PreRender 中,两者都产生相同的错误。我究竟做错了什么?