How to change TextBox Border Width, Style, Color in ASP.NET
17 December 2022

How to change TextBox Border Width, Style, Color in ASP.NET

By

– 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">
                &nbsp;</td>
            <td style="width: 100px">
                &nbsp;</td>
            <td style="width: 100px">
                &nbsp;</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">
                &nbsp;</td>
            <td style="width: 100px">
                &nbsp;</td>
            <td style="width: 100px">
                &nbsp;</td>
            </tr>
            <tr>
            <td colspan="3" style="text-align: center">
            &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Border width" BackColor="#FF6600" ForeColor="#FFFF66" />
            &nbsp;<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Border Style" BackColor="#FF6600" ForeColor="#FFFFCC" />
            &nbsp;<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Border color" BackColor="#FF6600" ForeColor="White" />
            &nbsp;<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 :

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:

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.

change Textbox BorderStyle in ASP.NET – ASP.NET Textbox Example
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.BorderStyle = BorderStyle.Double;
}
The ASP.NET Textbox border color change Result is:
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;
}

Prev Post

Download ►Adobe Photoshop CC 2022

Next Post

How to Change TextBox Control…

post-bars