In ASP.NET some time we need some control that can be used for collecting information from the user. ASP.NET has some control for collecting user information and out of these controls one control is text box control. So we can say that the text box control is information collector control.
How to use text box control – Step by Step Guide
First click on toolbox list shown in your Visual Studio (VS) Framework. Then you may see text box control there. Just drag this control to your web form or you may double click on it to insert in your web form. When you insert text box control in your web form then you may see following coding:
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
When you run this very very simple program then you may see an empty text box on your web page.
Properties of text box control
Text box control has various properties. Let’s study them here.
- TextMode: This property is used to change the text mode of a text box. Text box attribute has 3 values MultiLine, Password and SingleLine.
<asp:TextBox ID=”TextBox1″ runat=”server” TextMode=”MultiLine”></asp:TextBox>
When textbox TextMode value is set to MultiLine then textbox is shown in the form of a multiline textbox. This is used when large piece of content is required to fetch from user like address, description or any other lengthy information.
When TextMode value is set to Password then the textbox is used to get password from user. This is used in login form in a web form.
And the last one is SingleLine value. This is default value. If you don’t use TextMode property then by default the TextMode is SingleLine, so there is no need to write this manually.
MaxLength: This attribute is used to fix the length of textbox. This attribute is given any integer number as value. If it is set to 50 then in textbox no more than 50 characters can be added.
ReadOnly: This attribute has to values namely true and false. If it is set to true then user can not type anything in textbox else he can write in it.
Text: This attribute is used to write any thing in textbox by default.
TabIndex: This attribute is used when textbox are accessed from tab key. TabIndex are given Positive Integers values like 1,2,3,4 etc. If there are 2 or more than 2 textbox and they have TabIndex value 1,2,3,4 respectively then when we press tab key then cursor moves from textbox having TabIndex value 1 to TabIndex value 2 and then to TabIndex value 3 end so on.
Columns and Rows: This property of textbox control is used to set the length of height of a textbox indirectly. The number of columns is equal to characters which are enter in the textbox. Similarly rows are the number of lines of textbox in which user can input the data.
Besides there are some common properties like width, height, font, Visible, Enabled are also there which are not required to discuss here.
Following is some sample coding
<asp:TextBox ID=”TextBox1″ runat=”server” TextMode=”MultiLine” MaxLength=”50″ TabIndex=”2″></asp:TextBox>
<asp:TextBox ID=”a12″ runat=”server” TabIndex=”3″ ></asp:TextBox>
<asp:TextBox ID=”TextBox2″ runat=”server” TabIndex=”1″ ></asp:TextBox>
That’s all textbox control in brief. Happy coding J