Change Button Text Color Programmatically
Button is an asp.net web server control. this server control allow us to create a push button
on the web page that lets users to post a web page to the server. button server control have built in
property to set or change its default text color.
button control's ForeColor property allow us to get or set the button's text color (font color or foreground color). this property value type is System.Drawing.Color. this property value represents a color to display as button text color. we need to import System.Drawing namespace to assign a color as button text color.
the following asp.net c# example code demonstrate us how can we apply a color as button text color dynamically at run time in an asp.net application.
button control's ForeColor property allow us to get or set the button's text color (font color or foreground color). this property value type is System.Drawing.Color. this property value represents a color to display as button text color. we need to import System.Drawing namespace to assign a color as button text color.
the following asp.net c# example code demonstrate us how can we apply a color as button text color dynamically at run time in an asp.net application.
ButtonForeColor.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button2_Click(object sender, System.EventArgs e)
{
Button1.ForeColor = System.Drawing.Color.Crimson;
}
protected void Button3_Click(object sender, System.EventArgs e)
{
Button1.ForeColor = System.Drawing.Color.DodgerBlue;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to set, change Button ForeColor (font, text color)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">Button Example: ForeColor</h2>
<asp:Button
ID="Button1"
runat="server"
Text="Test Button ForeColor"
Font-Bold="true"
Height="44"
/>
<br /><br />
<asp:Button
ID="Button2"
runat="server"
Text="ForeColor Crimson"
OnClick="Button2_Click"
/>
<asp:Button
ID="Button3"
runat="server"
Text="ForeColor DodgerBlue"
OnClick="Button3_Click"
/>
</div>
</form>
</body>
</html>


