Web server Controls->ASP.NET TextBox Control
Definition and Usage
The TextBox control is used to create a text box where the user can input text.
Properties
| Property | Description |
|---|---|
| AutoPostBack | A Boolean value that specifies whether the control is automatically posted back to the server when the contents change or not. Default is false |
| Columns | The width of the textbox |
| id | A unique id for the control |
| MaxLength | The maximum number of characters allowed in the textbox |
| OnTextChanged | The name of the function to be executed when the text in the textbox has changed |
| Rows | The height of the textbox (only used if TextMode="Multiline") |
| runat | Specifies that the control is a server control. Must be set to "server" |
| Text | The contents of the textbox |
| TextMode |
SingleLine 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:
|
| Wrap | A 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:
IF you enter the text "shaohai" instead of "Hello World!", it will shows:
|
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.
浙公网安备 33010602011771号