I'm using VS2010 C# ASP.NET
To programmatically change the ForeColor of an asp:Label named lblExample
to 'Red', I write this:
lblExample.ForeColor = System.Drawing.Color.Red;
After changing the ForeColor, how do I programmatically set the ForeColor of the label to its default (that comes from the css file)?
Remark: the label has no CSS entry (class or ID specific style). The color is inherited.
The ForeColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default.
Easy
if (lblExample.ForeColor != System.Drawing.Color.Red) { lblExample.ForeColor = System.Drawing.Color.Red; } else { lblExample.ForeColor = new System.Drawing.Color(); }
You can also use below format:
Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#22FF99");
and
HyperLink1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#22FF99");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With