我有一個組合控件,它將一個TextBox和一個Label控件添加到它的Controls集合中。當我嘗試將標籤的AssociatedControlID設置爲文本框的ClientID時,出現此錯誤在標籤上設置AssociatedControlID失敗
Unable to find control with id
'ctl00_MainContentPlaceholder_MatrixSetControl_mec50_tb'
that is associated with the Label 'lb'.
好吧,有點背景。我得到了這個主複合控件,它動態地爲其控件集合添加了許多「元素」。其中一個元素碰巧是這個'MatrixTextBox',它是由TextBox和Label組成的控件。
我保持標籤和文本框爲受保護的類變量,並在CreateChildControls中初始化它們:
ElementTextBox = new TextBox();
ElementTextBox.ID = "tb";
Controls.Add(ElementTextBox);
ElementLabel = new Label();
ElementLabel.ID = "lb";
Controls.Add(ElementLabel);
我嘗試添加控件以Controls集合,甚至後設置
ElementLabel.AssociatedControlID = ElementTextBox.ClientID;
都是正確的在PreRender中 - 都會產生相同的錯誤。我究竟做錯了什麼?
謝謝!該死的我現在感到很蠢:) – 2008-10-22 08:08:49
@Hojou:哦,...類似的錯誤一直髮生在我身上。很明顯,如果你看到解決方案... – splattne 2008-10-22 08:15:56