TextBox 控件用于创建用户可输入文本的文本框。
属性 | 描述 | .NET |
---|---|---|
AutoCompleteType | 规定 TextBox 控件的 AutoComplete 行为。 | 2.0 |
AutoPostBack | 布尔值,规定当内容改变时,控件是否自动回传到服务器。默认是 false。 | 1.0 |
CausesValidation | 规定当 Postback 发生时,是否验证页面。 | 2.0 |
Columns | textbox 的宽度。 | 1.0 |
MaxLength | 在 textbox 中所允许的最大字符数。 | 1.0 |
ReadOnly | 规定能否改变文本框中的文本。 | 1.0 |
Rows | textbox 的高度(仅在 TextMode="Multiline" 时使用)。 | 1.0 |
runat | 规定该控件是否是服务器控件。必须设置为 "server"。 | |
TagKey | ||
Text | textbox 的内容。 | 1.0 |
TextMode | 规定 TextBox 的行为模式(单行、多行或密码)。 | 1.0 |
ValidationGroup | 当 Postback 发生时,被验证的控件组。 | |
Wrap | 布尔值,指示 textbox 的内容是否换行。 | 1.0 |
OnTextChanged | 当 textbox 中的文本被更改时,被执行的函数的名称。 |
- AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width
- AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible
Textbox
- <script runat="server">
- Sub submit(sender As Object, e As EventArgs)
- lbl1.Text="Your name is " & txt1.Text
- End Sub
- </script>
- <!DOCTYPE html>
- <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>
在本例中,我们在 .aspx 文件中声明了一个 TextBox 控件,一个 Button 控件,和一个 Label 控件。当提交按钮被触发时,会执行 submit 子例程。这个 submit 子例程会向 Label 控件输出文本。
Textbox 2
- <script runat="server">
- sub submit(sender As Object, e As EventArgs)
- lbl1.Text=txt1.Text
- end sub
- </script>
- <!DOCTYPE html>
- <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>
在本例中,我们在 .aspx 文件中声明了一个 TextBox 控件,一个 Button 控件,和一个 Label 控件。当提交按钮被触发时,会执行 submit 子例程。这个 submit 子例程会把文本框的内容拷贝到 Label 控件。