title: Unable to cast object of type 'ASP.site_master' to type 'System.Web.UI.WebControls.Button'. in asp.net
body: <p>I just created ten buttons and last two buttons named btn_green and btn_red,.</p>
  
  <p>I wanna to change all button color to the green and red when click those buttons green and red.</p>
  
  <p>My C# code is</p>
  
  <pre><code>protected void btn_green_Click(object sender, EventArgs e)
          {
              foreach (Button btn in this.Controls)
              {
                  btn.BackColor = Color.DarkGreen;
              }
          }     
  
          protected void btn_red_Click(object sender, EventArgs e)
          {
              foreach (Button btn in this.Controls)
              {
                  btn.BackColor = Color.Red;
              }
          }
  </code></pre>
  
  <p>but my bed luck i got only error </p>
  
  <blockquote>
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.InvalidCastException: Unable to cast object
    of type 'ASP.site_master' to type 'System.Web.UI.WebControls.Button'.</p>
  </blockquote>
  
  <pre><code>Line 20:             foreach (Button btn in this.Controls)
  </code></pre>
  
  <p>how i escape this problem?.</p>