找到一个ASP.NET面板中的所有控件? [英] Finding all controls in an ASP.NET Panel?
本文介绍了找到一个ASP.NET面板中的所有控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有在我的网页若干板,其中我收集用户信息,并保存在网页的信息。页面面板有文本框,下拉列表,列表框。
I am having a number of panels in my page in which I am collecting user information and saving the page details. The page panel has textbox, dropdown list, listbox.
当我需要来到这个页面。我需要显示的页面,如果这些控件有任何价值。如何做到这一点?
When I need to come to this page. I need to show the Page if these controls have any values. How to do this?
推荐答案
它归结为在控制层次枚举所有的控件:
It boils down to enumerating all the controls in the control hierarchy:
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
您可以使用它是这样的:
You can use it like this:
foreach (Control c in EnumerateControlsRecursive(Page))
{
if(c is TextBox)
{
// do something useful
}
}
这篇关于找到一个ASP.NET面板中的所有控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文