Change TextBox control Font and Style Programmatically in ASP.Net
In this post we are going to learn how to change TextBox Control Font Size, TextBox Color, Background all style of Textbox control in ASP.Net TextBox Example.
First, Design the Page with One TextBox control along with 2 Button Control.
Write below code in Body tag :
<table style=”width: 376px”>
<tr>
<td style=”width: 100px; text-align: right”>
Enter Value:
</td>
<td colspan=”2″ style=”text-align: left”>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox></td>
</tr>
<tr>
<td colspan=”3″ style=”height: 26px”>
<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Style1″
Width=”80px” />
<asp:Button ID=”Button2″ runat=”server” OnClick=”Button2_Click” Text=”Style2″ Width=”80px” /></td>
</tr>
</table>
The Design form look like below screen.
– Now write the Below code in Style1 Button Click Event:
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.ForeColor = System.Drawing.Color.Red;
TextBox1.Font.Size = 17;
TextBox1.Font.Bold = true;
TextBox1.BackColor = System.Drawing.Color.Yellow;
}
The ASP.NET TextBox Example Output is :
– Write Below code in Style2 Button Click Event :
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.ForeColor = System.Drawing.Color.Green;
TextBox1.BackColor = System.Drawing.Color.White;
TextBox1.Font.Underline = true;
TextBox1.Font.Italic = true;
TextBox1.Font.Bold = false;
}
The ASP.Net TextBox Example Result is :
– In this ASP.NET Texbox Example post we got the knowledge about how to change TextBox Font Size and all Textbox style in ASP.Net
– Hope you enjoyed this ASP.Net TextBox Example Tutorials.