February 19, 2009


In ASP.NET, the textbox control is a web server control. This control allows
user to enter text. The text can then be validated and processed on the server
side.


The TextBox control can be used in a web page by simply dragging the TextBox in
the Toolbox > Standard section in Visual Web Developer. While dragging the
control, the following code is created


<
asp:TextBox ID="TextBox" runat="server"></asp:TextBox>


Note that the ID refers to the ID of the control and runat=”server” means that
the control will be run on the server side. By default, the control will be
rendered as a single line textbox similar to HTML
<input type="“text”" />
control.


To display the TextBox control as a HTML text-area control use the code

<
asp:TextBox

ID="TextBox" runat="server" TextMode="MultiLine"></asp:TextBox>


To display it as password text-field, use the following code

<asp:TextBox
ID="TextBox" runat="server" TextMode="Password"></asp:TextBox>


To set the width of the TextBox control, use either of the following code,

<
asp:TextBox ID="TextBox" runat="server" Width="100px"></asp:TextBox>

Or

<
asp:TextBox ID="TextBox" runat="server" Columns="20"></asp:TextBox>


To set the height of the TextBox control, use either of the following code,

<asp:TextBox ID="TextBox" runat="server" Rows="10"></asp:TextBox>

Or

<asp:TextBox ID="TextBox" runat="server" Height="100px"></asp:TextBox>


To set the border properties of the TextBox control, use the following code,

<asp:TextBox
ID="TextBox" runat="server" BorderColor="Red" BorderStyle="Dotted" BorderWidth="1px"></asp:TextBox>


The following border styles are available,
  • Dotted
  • Dashed
  • Double
  • Solid
  • Groove
  • Inset
  • Outset
  • None
  • Notset
  • Ridge



To set the font properties, use the following code,

<asp:TextBox ID="TextBox" runat="server" Font-Bold="true" Font-Italic="true" Font-Names="Trebuchet MS" Font-Size="Medium" Font-Underline="True" Strikeout="True"></asp:TextBox>


To set the fore and back color of the TextBox control, use the following code,

<asp:TextBox ID="TextBox" runat="server" BackColor="Red" ForeColor="Blue"></asp:TextBox>


To set the tab index, use the following code,

<asp:TextBox ID="TextBox" runat="server" TabIndex="4"></asp:TextBox>


To set the access key, use the following code,

<asp:TextBox ID="TextBox" runat="server" AccessKey="K"></asp:TextBox>


To set the AutoPostBack property, use the following line,

<asp:TextBox ID="TextBox" runat="server" AutoPostBack="true"></asp:TextBox>


To disable or enable the TextBox control, set the Enabled or ReadOnly property as follows.

<asp:TextBox ID="TextBox" runat="server" Enabled="false"></asp:TextBox>

Or

<asp:TextBox ID="TextBox" runat="server" ReadOnly="true"></asp:TextBox>


To enable or disable the ViewState, use the following code,

<asp:TextBox ID="TextBox" runat="server" EnableViewState="true"></asp:TextBox>


To set the maximum number of characters entered in the TextBox control, use the
following line,

<asp:TextBox ID="TextBox" runat="server" MaxLength="10"></asp:TextBox>


To set the tool-tip property of the textbox, use the following code,

<asp:TextBox ID="TextBox" runat="server" ToolTip="tool tip"></asp:TextBox>

0 comments:

Reference: Shahed Kazi at AspNetify.com