您的位置:首页 > 编程语言 > ASP

Web server Controls->ASP.NET TextBox Control

2007-03-27 17:18 441 查看

Definition and Usage

The TextBox control is used to create a text box where the user can input text.

Properties

PropertyDescription
AutoPostBackA Boolean value that specifies whether the control is automatically posted back to the server when the contents change or not. Default is false
ColumnsThe width of the textbox
idA unique id for the control
MaxLengthThe maximum number of characters allowed in the textbox
OnTextChangedThe name of the function to be executed when the text in the textbox has changed
RowsThe height of the textbox (only used if TextMode="Multiline")
runatSpecifies that the control is a server control. Must be set to "server"
TextThe contents of the textbox
TextModeSingleLine creates a text box with only one line. MultiLine creates a text box with multiple lines. Password creates a one-line text box that masks the value entered by the user. Default is SingleLine. Legal values are:

SingleLine
MultiLine
Password

WrapA Boolean value that indicates whether the contents of the textbox should wrap or not

Examples

Textbox
ASPX Source:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

Output Result:

Enter your name:

IF you enter your name "shaohai" into the textbox , it will shows:

Enter your name:
Your name is shaohai

In this example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine writes a text to the Label control.

Textbox 2
ASPX Source:

<script runat="server">
sub submit(sender As Object, e As EventArgs)
lbl1.Text=txt1.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:TextBox id="txt1" Text="Hello World!"
Font_Face="verdana" BackColor="#0000ff"
ForeColor="white" TextMode="MultiLine"
Height="50" runat="server" />
<asp:Button OnClick="submit"
Text="Copy Text to Label" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>
Output Result:

Hello World!

IF you enter the text "shaohai" instead of "Hello World!", it will shows:

shaohai
shaohai

In this example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine copies the contents of the textbox to the Label control.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: