I have a page that has 5 user controls. I want to do more with them, but for now, I just want to count them using the following method.
void btnFormSave_Click(object sender, EventArgs e)
{
int i = 0;
ControlCollection collection = Page.Controls;
foreach (Control ctr in collection)
{
if (ctr is UserControl)
{
i++;
}
}
}
When I debug this code, i = 1, and the control is the master page (I didn't know that the master page is a user control).
How do I count user controls that are on my page?
EDIT
This is my content placeholder markup.
<asp:Content ID="cntMain" runat="Server" ContentPlaceHolderID="ContentMain">