title: How to count the number of user controls that I have in a page?
body: <p>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.</p>
  
  <pre><code>void btnFormSave_Click(object sender, EventArgs e)
  {
    int i = 0;
    ControlCollection collection = Page.Controls;
    foreach (Control ctr in collection)
    {
      if (ctr is UserControl)
      {
        i++;
      }
     }
  }
  </code></pre>
  
  <p>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).</p>
  
  <p>How do I count user controls that are on my page?</p>
  
  <h1>EDIT</h1>
  
  <p>This is my content placeholder markup.</p>
  
  <pre><code>&lt;asp:Content ID="cntMain" runat="Server" ContentPlaceHolderID="ContentMain"&gt;
  </code></pre>