Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change the font color of a label when I click on a radio button. I am using web form in Visual Studio 2015.

What I have tried:

I have tried label1.forecolor = "Black", label1.forecolor = 00,00,00. and various other combinations.
Posted
Updated 19-Jul-16 19:50pm
v2
Comments
ZurdoDev 19-Jul-16 14:58pm    
You'll likely want to do it in JavaScript.

1 solution

refer this

ASP.NET
<asp:RadioButtonList ID="rbcolor" AutoPostBack="true" runat="server" OnSelectedIndexChanged="rbcolor_SelectedIndexChanged"  >
           <asp:ListItem Text="Red" />
           <asp:ListItem Text="Green" />
           <asp:ListItem Text="Blue" />
       </asp:RadioButtonList>
       <asp:Label Text="My Label" ID="lblColor" runat="server" />

VB.NET
Protected Sub rbcolor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbcolor.SelectedIndexChanged
       If (rbcolor.SelectedValue = "Red") Then
           lblColor.ForeColor = System.Drawing.Color.Red
       ElseIf (rbcolor.SelectedValue = "Green") Then
           lblColor.ForeColor = System.Drawing.Color.Green
       ElseIf (rbcolor.SelectedValue = "Blue") Then
           lblColor.ForeColor = System.Drawing.Color.Blue
       End If

   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900