The TextBox control is used to create a text box for users to enter text.
The properties and features of TextBox are listed in our web control Reference Manual.
The following example demonstrates some attributes of the TextBox control that you may use:
<Html>
<Body>
<Form runat = "server">
Basic TextBox:
<Asp Tutorial: TextBox id = "tb1" runat = "server"/>
<Br/>
TextBox used to enter the password:
<Asp: TextBox id = "tb2" TextMode = "password" runat = "server"/>
<Br/>
TextBox with text:
<Asp: TextBox id = "tb4" Text = "Hello World! "Runat =" server "/>
<Br/>
TextBox with multiple rows:
<Asp: TextBox id = "Int32" TextMode = "multiline" runat = "server"/>
<Br/>
TextBox with height:
<Asp: TextBox id = "tb6" rows = "5" TextMode = "multiline"
Runat = "server"/>
<Br/>
TextBox with width:
<Asp: TextBox id = "tb5" columns = "30" runat = "server"/>
</Form>
</Body>
</Html>
During Web development, you may also encounter problems that I encountered before. When using the TextBox control, the edge of the control cannot be completely overwritten by the background image, as shown in Figure 1:
After Textbox resolution, it is also an html-Text control, while the Text control has edges by default, that is, border: 1px solid #000;
Therefore, you only need to add the following small CSS for the Textbox control, that is, "border: 0px". The final effect is shown in Figure 2:
② When you are doing Web development, I wonder if you have found that when TextMode = "MultiLine" of the Textbox control is replaced, MaxLength has actually expired.
When the TextMode attribute of Textbox is "MultiLine", it is actually the html-textarea control after parsing. This html control does not have the MaxLength attribute.
If you want to limit the input length, you can set the following attributes:
<Asp: TextBox ID = "maid" runat = "server" TextMode = "MultiLine" onkeyup = "this. value = this. value. slice (0, 1000)">
③ When you make some input boxes, you may want to trigger an event when you get the focus, or trigger an event when you lose focus:
I wrote two JS files to meet the following requirements:
<Script type = "text/webpage effects">
// Triggered when the focus is obtained
Function onFocusFun (element, elementValue ){
If (element. value = elementValue ){
Element. value = "";
Element. style. color = "";
}
}
// Triggered when the input box is left.
Function onblurFun (element, elementValue ){
If (element. value = ''){
Element. style. color = "#808080 ";
Element. value = elementValue;
}
}
</Script>
Then, you can reference them in the Textbox control as follows:
<Asp: TextBox ID = "reply_note" runat = "server" Text = "post reply, up to 1000 words entered" ForeColor = "#808080" OnFocus = "onFocusFun (this, 'Post reply, up to 1000 words ')"
OnBlur = "onblurFun (this, 'post reply, up to 1000 words')"> </asp: TextBox>