Asp. NET textbox text input Box control using method _ Basic Application

Source: Internet
Author: User

The TextBox control, also known as a text box control, provides the user with the ability to enter text.

1. Property

Common Properties and descriptions for TextBox controls are shown in table 1.

Table 1 Common Properties and descriptions for TextBox controls

Property Description
AutoPostBack Gets or sets a value that indicates whether the automatic postback to the server occurs whenever a user presses the 〈enter〉 key or 〈tab〉 key in a TextBox control
CausesValidation Gets or sets a value that indicates whether validation is performed when the TextBox control is set to authenticate when a postback occurs
Id Control ID
Text The text to display for the control
TextMode Gets or sets the behavior mode (single, multiline, or password) of a TextBox control
Width Width of control
Visible Control is visible
ReadOnly Gets or sets a value that indicates whether the contents of a TextBox control can be read-only
CssClass The style that the control renders
BackColor control's background color
Enabled Control is available

The TextBox control most of the property settings are similar to the label control, see the Label control property settings, the following is a brief introduction to the TextMode property.

The TextMode property is primarily used to control the text display of a TextBox control, with the following 3 options for setting the property.

Single line (singleline): Users can enter information only on one line, and optionally limit the number of characters that the control receives.

MultiRow (MultiLine): Allows the user to enter multiple lines of text and perform line wrapping when the text is long.

Password (Password): Masks the characters entered by the user with a black dot () to hide the information.

For example, when validating a user logon password, you can set the TextMode property of the TextBox control to password, which works as shown in Figure 1.

When you fill out notes, the text may be a lot, and you can set the TextMode property of the TextBox control to multiline, which runs as shown in Figure 2.

Figure 1 Hiding the login password

Figure 2 Fill in the memo material

2. Method

The common methods for TextBox controls are similar to label controls, and table 2 lists some of its common methods.

Table 2 Common methods and descriptions for TextBox controls

Method Description
DataBind Bind the data source to the invoked server control and all its child controls
Focus Set input focus for a control
Dispose Enables a server control to perform a final cleanup operation before releasing from memory
Equals Determine whether two object instances are equal

The focus method of a TextBox control is used primarily to obtain its focal point, for example: the user writes the following code in a Page_Load event that contains a TextBox control page:

Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
Textbox1.focus ();
}

The results of the operation are shown in Figure 3.

Figure 3 Getting the TextBox control focus

3. Event

The TextBox control common events are similar to the label controls, see the label control frequently used events.
4. Example

Example:

TextBox Control Sample

The following example compares the effect of a 3 TextBox control by setting a different TextMode property value. Create a new Web site, the default home page is default.aspx, add 3 TextBox controls on the Default.aspx page, and their properties are set as follows.

Enter the TextBox control for the user name: The TextMode property is set to the Singleline,backcolor property to #ffe0c0 (light yellow), and the BorderColor property is blue.

Enter a TextBox control for the password: The TextMode property is set to password.

Enter the TextBox control for the memo information: The TextMode property is set to Multiline.

Executes the program, entering text in 3 text boxes, and the sample runs as shown in Figure 4.

Figure 4 Example of a TextBox control

The complete code for the program is as follows:

Front desk default.aspx

Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


<title>textbox Control Sample </title>
<body>

<form id= "Form1" runat= "Server" >
<div>
User name: <asp:textbox id= "TextBox1" runat= "Server" backcolor= "#FFE0C0" bordercolor= "Blue"
Ontextchanged= "textBox1_TextChanged" ></asp:TextBox>
<br/>
Password: <asp:textbox id= "TextBox2" runat= "Server" textmode= "Password" width= "149px" ></asp:TextBox>
<br/>
Note: <asp:textbox id= "TextBox3" runat= "Server" textmode= "MultiLine" ></asp:TextBox></div>
</form>
</body>

Backstage Default.aspx.cs

Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}

protected void textBox1_TextChanged (object sender, EventArgs e)
{
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.