asp.net - How to change a Panel background color programmatically

Panel background color
Panel is an asp.net web server control. panel server control acts as a container control for other controls. panel control have a built in property to set or change its background color programmatically at run time.

panel BackColor property get or set the background color of panel server control. this BackColor property value type is System.Drawing.Color. the 'Color' represents the background color of panel server control. this property default value is Empty that indicate no color is set for panel background. we should import the System.Drawing namespace to assign panel background color programmatically.

the following asp.net c# example code demonstrate us how can we set or change panel server control's background color dynamically at run time in an asp.net application.
PanelBackColor.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Panel1.BackColor = Color.PaleVioletRed;

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Panel1.BackColor = Color.SandyBrown;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change Panel BackColor (BackGround color)</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Panel Example: BackColor</h2>
        <asp:Panel 
             ID="Panel1"
             runat="server"
             Height="150"
             Width="350"
             HorizontalAlign="Center"
             ForeColor="FloralWhite"
             BackColor="AntiqueWhite"
             >
             <br /><br />
             <h2>BackColor</h2>
        </asp:Panel>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Panel BackColor PaleVioletRed"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Panel BackColor SandyBrown"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples