How to set a button property for multiple buttons using foreach?
<p>I have 12 buttons in ASP.NET page. I want to color the button; But My code is not work. I will check with break point but   button.BackColor = Color.DarkGreen; code is not executed.</p>

<p><strong>ASP Design Coding -</strong></p>

<pre><code>  &lt;form id="form1" runat="server" style="background-color:Silver; height:100%; min-height:300px"&gt;   
       &lt;div style="height:100%;"&gt;
            &lt;div style="height:20%;"&gt;
            &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;    
        &lt;/div&gt;
        &lt;div id="content" runat="server" class="content" style="height:70%; min-height:180px"&gt;    
            &lt;div &gt;               
                &lt;asp:Button ID="Button1" runat="server" Text="Button"  style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button2" runat="server" Text="Button" style="width:32%" 
                    Enabled="False"/&gt;               
                &lt;asp:Button ID="btnUp" runat="server" Text="UP" onclick="btnUp_Click" style="width:32%" /&gt; &lt;br /&gt;&lt;br /&gt;
                &lt;asp:Button ID="Button3" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button4" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button5" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt; &lt;br /&gt;&lt;br /&gt;
                &lt;asp:Button ID="Button6" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button7" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button8" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt; &lt;br /&gt;&lt;br /&gt;
                &lt;asp:Button ID="Button9" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;
                &lt;asp:Button ID="Button10" runat="server" Text="Button" style="width:32%" 
                    Enabled="False" /&gt;            
                &lt;asp:Button ID="btnDown" runat="server" Text="DOWN" onclick="btnDown_Click" style="width:32%" /&gt; &lt;br /&gt;&lt;br /&gt;
            &lt;/div&gt;&lt;!-- /grid-b --&gt;        
        &lt;/div&gt;       
          &lt;div id="footer" class="footer" style="height:10%;"&gt;
             &lt;a href="OutLet.aspx" &gt;Home&lt;/a&gt;
             &lt;a href="Selection.aspx"&gt;Selection&lt;/a&gt;
        &lt;/div&gt;
        &lt;/div&gt;
    &lt;/form&gt;
</code></pre>

<p>*<strong>C# Coding - *</strong></p>

<pre><code>var buttons = this.form1.Controls.OfType&lt;Button&gt;();
        foreach (var button in buttons)
        {
           button.BackColor = Color.DarkGreen;
        }
</code></pre>
