asp.net - How to change a TextBox text color programmatically

TextBox font, text color
Colored text are more attractive for user. It is very positive design to use colored text for kids web site. In this example we will see how can we set or change TextBox font color programmatically. ASP.NET TextBox web server control ForeColor property help us to change TextBox text color.

Following source code create a TextBox and two button control. When someone click a Button, then TextBox change it's text color. System.Drawing namespace help us to get standard color enumeration. Using color enumeration we can get many colors such as red, green, blue, magenta, yellow etc.
TextBoxForeColor.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TextBox ForeColor (font, text color)</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">TextBox Example: ForeColor</h2>
        <asp:Label 
             ID="Label1" 
             runat="server"
             Text="City Name"
             >
        </asp:Label>
        <asp:TextBox 
             ID="TextBox1" 
             runat="server"
             Text="Your City Name Here"
             Font-Bold="true"
             >
        </asp:TextBox>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             ForeColor="DarkCyan"
             Text="TextBox ForeColor MediumBlue"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server" 
             Font-Bold="true"
             ForeColor="DarkCyan"
             Text="TextBox ForeColor HotPink"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples