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:

<table>
<tr>
<td style=”width: 100px; text-align: right”>
Enter Value :</td>
<td style=”width: 100px”>
<asp:TextBox ID=”TextBox1″ runat=”server” CssClass=”txt”></asp:TextBox></td>
<td style=”width: 100px”>
</td>
</tr>
<tr>
<td colspan=”3″>
&nbsp;<asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Border width” />
<asp:Button ID=”Button2″ runat=”server” OnClick=”Button2_Click” Text=”Border Style” />
<asp:Button ID=”Button3″ runat=”server” OnClick=”Button3_Click” Text=”Border color” /></td>
</tr>
</table>

The design layout look like below screen :

How to change Textbox borderwith, style and color in ASP.NET

How to change Textbox borderwith, style and color in ASP.NET

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:

protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.BorderColor = System.Drawing.Color.Red;
}

The ASP.NET Textbox border color change Result is:

Change Textbox bordercolor in ASP.NET - ASP.NET Textbox Example

Change Textbox bordercolor in ASP.NET – ASP.NET Textbox Example

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 = 7;
}

The output of changed Textbox border width is below:

Change Textbox border width in ASP.NET - ASP.NET Textbox Example

Change Textbox border width in ASP.NET – ASP.NET Textbox Example

- 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;
}

The ASP.NET Textbox Border Style changed output is:

change Textbox BorderStyle in ASP.NET - ASP.NET Textbox Example

change Textbox BorderStyle in ASP.NET – ASP.NET Textbox Example

- I hope you enjoyed to learn this ASP.NET Textbox Example change Border Style, Textbox Border width, Textbox Bordercolor Programmatically in ASP.NET.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 8 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">