In this ASP.Net post, we show you how to change the Label Text color according to change the Checkbox check status.
STEP 1- Design the ASP.Net web page with Three Checkbox control and one Label Control :
<table border=”1″ bordercolor=”#000000″ style=”z-index: 100; left: 272px; position: absolute;
top: 72px”>
<tr>
<td colspan=”3″ style=”width: 582px”>
<asp:Image ID=”Image1″ runat=”server” ImageUrl=”https://meeraacademy.com/wp-content/themes/elemin/uploads/logo/meeralogo.gif” /></td>
</tr>
<tr>
<td colspan=”3″ rowspan=”2″ style=”width: 582px; height: 21px; text-align: center”>
<table>
<tr>
<td colspan=”2″ style=”height: 24px; text-align: center”>
<strong>Change Color according to CheckBox</strong></td>
</tr>
<tr>
<td style=”width: 181px; height: 24px; text-align: right;”>
</td>
<td style=”width: 255px; height: 24px;”>
<asp:CheckBox ID=”chkRed” runat=”server” Text=”Red” Font-Bold=”True” AutoPostBack=”True” OnCheckedChanged=”chkRed_CheckedChanged” />
<asp:CheckBox ID=”chkblue” runat=”server” Font-Bold=”True” Text=”Blue” AutoPostBack=”True” OnCheckedChanged=”chkblue_CheckedChanged” />
<asp:CheckBox ID=”chkGreen” runat=”server” AutoPostBack=”True” Font-Bold=”True” OnCheckedChanged=”chkGreen_CheckedChanged”
Text=”Green” /></td>
</tr>
<tr>
<td style=”width: 181px”>
</td>
<td style=”width: 255px”>
<asp:Label ID=”lblanswer” runat=”server” Font-Bold=”True”></asp:Label></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>
STEP 2 – write the below code at coding page on ASP.Net aspx.cs page:
protected void chkRed_CheckedChanged(object sender, EventArgs e)
{
lblanswer.Text = “RED”;
lblanswer.ForeColor = System.Drawing.Color.Red;
chkblue.Checked = false;
chkGreen.Checked = false;
}
protected void chkblue_CheckedChanged(object sender, EventArgs e)
{
lblanswer.Text = “BLUE”;
lblanswer.ForeColor = System.Drawing.Color.Blue;
chkRed.Checked = false;
chkGreen.Checked = false;
}
protected void chkGreen_CheckedChanged(object sender, EventArgs e)
{
lblanswer.Text = “GREEN”;
lblanswer.ForeColor = System.Drawing.Color.Green;
chkRed.Checked = false;
chkblue.Checked = false;
}
The ASP.Net Checkbox Example output is :
The ASP.Net Checkbox Example output is :
The ASP.Net Checkbox Example output is :