this.Controls doesn't contain all controls

落爺英雄遲暮 提交于 2019-12-08 11:28:39

问题


One text box in particular has been skipped. That textbox with ID "q3TXT" is inside a panel which is hidden at the PageLoad method.

Yet it becomes visible before the function that collects controls.

Every other textbox is collected.

I've tried with IEnumberable collection of textboxes, which didn't work.

How can I make the textbox appear in the controls list?

Here is html:

<p id="question3Text" runat="server" class="question"></p>
<asp:RadioButtonList runat="server" ID="q3_RBList" AutoPostBack="true" OnSelectedIndexChanged="q3_RBList_SelectedIndexChanged">
</asp:RadioButtonList>
<asp:Panel runat="server" ID="q3Panel">
    <p>If no, when did data collection stop?</p>
    <asp:TextBox runat="server" ID="q3TXT"></asp:TextBox>
</asp:Panel><br /><br />

And a part of c# code:

foreach (var item in this.Controls.OfType<TextBox>())
{
    //some code
}

回答1:


that specific textBox is a part of your specific panel so you should look for it inside of panel.Controls instead of this.Controls



来源:https://stackoverflow.com/questions/16538788/this-controls-doesnt-contain-all-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!