【发布时间】:2013-01-16 01:27:19
【问题描述】:
我有一个包含 5 个用户控件的页面。我想用它们做更多的事情,但现在我只想用下面的方法来统计它们。
void btnFormSave_Click(object sender, EventArgs e)
{
int i = 0;
ControlCollection collection = Page.Controls;
foreach (Control ctr in collection)
{
if (ctr is UserControl)
{
i++;
}
}
}
我调试这段代码的时候,i=1,控件就是母版页(不知道母版页是用户控件)。
如何计算页面上的用户控件?
编辑
这是我的内容占位符标记。
<asp:Content ID="cntMain" runat="Server" ContentPlaceHolderID="ContentMain">
【问题讨论】:
-
为什么需要统计用户控件的数量?
标签: asp.net user-controls