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

Change CheckBox background color programmatically
CheckBox is an asp.net web server control. this web server control allow users to select a true or false condition (checked and unchecked status). checkbox control have a built in property to set or change its background color programmatically at run time.

checkbox BackColor property get or set the checkbox background color. this BackColor property value type is System.Drawing.Color. this 'Color' can be any valid color such as Red, Yellow, HotPink etc and it represents the background color of checkbox control. we need to import System.Drawing namespace to assign checkbox background color programmatically.

the following asp.net c# example code demonstrate us how can we set or change the checkbox background color dynamically at run time in an asp.net application.
CheckBoxBackColor.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        CheckBox1.BackColor = System.Drawing.Color.SeaGreen;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        CheckBox1.BackColor = System.Drawing.Color.HotPink;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to change CheckBox BackColor (background color) programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">CheckBox Changed BackColor</h2>
        <asp:CheckBox
             ID="CheckBox1" 
             runat="server"
             Text="Check The CheckBox."
             AutoPostBack="false"
             Font-Bold="true"
             />
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             ForeColor="HotPink"
             Text="SeaGreen Background Color"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server" 
             Font-Bold="true"
             ForeColor="HotPink"
             Text="HotPink Background Color"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>








Related asp.net examples