this.Controls不包含所有控件 [英] this.Controls doesn't contain all controls

查看:93
本文介绍了this.Controls不包含所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尤其是一个文本框已被跳过。该ID为 q3TXT的文本框位于面板内,该面板在PageLoad方法中隐藏。

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.

我尝试使用IEnumberable文本框集合,但无法正常工作。

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

如何使文本框出现在控件列表中?

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

此处是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 />

还有C#代码的一部分:

And a part of c# code:

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


推荐答案

特定的 textBox 是您特定的 panel 的一部分,因此您应该在 panel.Controls 而不是 this.Controls

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

这篇关于this.Controls不包含所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆