How to change asp.net TextBox width programmatically

How to set, change TextBox width programmatically
are you want to change textbox control's width programmatically? this example show you how can you change textbox width on run time (programmatically). asp.net textbox web server control have a built in property named Width. you can change the textbox width by assigning this Width property value. Width property only accept numeric value.
TextBoxWidth.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        TextBox1.Width = 200;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        TextBox1.Width = 250;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change TextBox width programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">TextBox Example: Width</h2>
        <asp:Label 
             ID="Label1" 
             runat="server"
             Text="Favorite Actor"
             >
        </asp:Label>
        <asp:TextBox 
             ID="TextBox1" 
             runat="server"
             BackColor="LightGoldenrodYellow"
             >
        </asp:TextBox>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             ForeColor="DarkMagenta"
             Text="TextBox Width 200"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server" 
             Font-Bold="true"
             ForeColor="DarkMagenta"
             Text="TextBox Width 250"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
Related asp.net example