How to change TextBox Border Width, Style, Color in ASP.NET
– Hi, In this ASP.NET Example we will learn how to change TextBox Control Border Style, Border width and border color in programmatically in ASP.NET.
– First the Design the webfor with one TextBox along with the 3 button control in ASP.NET.
For Design, write the below code in Body tag:
<form id="form1" runat="server">
<center>
<table width="650" class="auto-style1">
<tr>
<td colspan="3" style="text-align: center;background-color:#FF6600;color:white;padding:15px;">
<h3>How to change TextBox Border Width, Style, Color in ASP.NET</h3></td>
</tr>
<tr>
<td style="width: 100px; text-align: right">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px; text-align: right">
Enter Value :</td>
<td style="width: 100px; text-align:center;">
<asp:TextBox ID="TextBox1" runat="server" CssClass="txt" Height="21px" Width="200px"></asp:TextBox></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px; text-align: right">
</td>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="3" style="text-align: center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Border width" BackColor="#FF6600" ForeColor="#FFFF66" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Border Style" BackColor="#FF6600" ForeColor="#FFFFCC" />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Border color" BackColor="#FF6600" ForeColor="White" />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Normal" BackColor="#FF6600" ForeColor="White" /></td>
</tr>
</table>
</center>
</form>
The design layout look like below screen :
Now we have Three Button control one for Change the TextBox width, second for Change the Textbox Style and last one is for Change the Textbox Border color.
Fist we change the Textbox Border color programmatically in ASP.NET C#.
For change the Textbox bordercolor write below code in Button Click event:
Now we will learn to change the border width of Textbox control in ASP.NET. write below code for change the Textbox border width in ASP.NET
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.BorderWidth = 10;
}
– Now last change the Textbox Style programatically in ASP.NET C#.
– write this code for change the Textbox border style in Button Click Event.
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.BorderStyle = BorderStyle.Double;
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.BorderColor = System.Drawing.Color.Orange;
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox1.BorderColor = System.Drawing.Color.Black;
TextBox1.BorderWidth = 1;
TextBox1.BorderStyle = BorderStyle.Solid;
}