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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
- How to set, change TextBox font size
- How to set, change TextBox ForeColor (font, text color)
- How to set, change TextBox height programmatically
- How to show, hide, visible TextBox programmatically
- How to set, change TextBox font, text style
- How to set, change Button BackColor (background color)
- How to set, change Button border color programmatically
- How to set, change Button border style programmatically
- How to enable, disable Button programmatically