Creating a regular text box
The TextBox Web server control provides a way for users to type information into a Web Forms page, including text, numbers, and dates.
This “all mighty” control replaces the distinct Text and Password type <input> controls as well as the TextArea control used by HTML.
The properties of the TextBox control enable you to configure the control to perform functions equal to those of HTML elements it replaces.
When you drop a TextBox control on a Web Form, the generated HTML in the “aspx” view will look like:
<asp:textbox id=TextBox1 runat="server"> </asp:textbox>
By default, the TextBox control renders as a single-line entry box.
The following properties determine the actual rendering and functionality of the TextBox control:
- Text is used to get or set (on the server) the text displayed/entered in the control.
- TextMode is a TextBoxMode value property. This enumeration represents the different display options for the TextBox control. Setting TextMode to TextBoxMode.SingleLine displays the TextBox as a single row (default). TextBoxMode.Password is similar to SingleLine, except that the control displays a special character in place of any entered text. TextBoxMode.MultiLine transforms the TextBox control into a TMemo like control.
When TextMode is set to TextBoxMode.MultiLine, the Rows property determines the actual height (in characters) of the control. The Height property determines the height in pixels. Note that, if the Height property is specified, the Rows property is ignored. What’s more, the Wrap property determines whether the text entered in the control will automatically wrap. Finally, scroll bars will appear if the text entered exceeds the physical size of the TextBox.
- MaxLenght specifies the maximum number of characters the user can enter into the control.
- ReadOnly determines whether the data in the TextBox can be edited.
- AutoPostback specifies whether the Web Form is automatically submitted (as if any of the button-like controls were clicked) when the content of the control is changed. Note that the control will “fire” a postback (if AutoPostback is set to True) only when the user leaves the control, NOT while editing the content (typing into the control).