|
TextBox
The TextBox Web Server control is used to accept input from the user. They appear
like a box and allows the user to enter some text, like, username, password, etc.
The class hierarchy for this control is as follows:
Object
Control
WebControl
TextBox
Below is a ReadOnly TextBox with BackColor property set
to Silver, BorderColor property set to Brown and BorderStyle property
set to solid.
Notable properties
Notable properties of the TextBox control are as follows:
AutoPostBack: Gets/Sets whether events will be automatically
posted to the server
Columns: Gets/Sets the textbox's width in columns
MaxLength: Gets/Sets the maximum number of characters that
can be displayed in the textbox
ReadOnly: Gets/Sets whether the textbox is readonly
Rows: Gets/Sets a multiline textbox's display height
Text: Gets/Sets the text in a textbox
TextMode: Gets/Sets whether a textbox should be single line,
multiline or a password control
Wrap: Gets/Sets whether text wraps in a textbox
Code Examples
Sample 1
Drag a TextBox and a Button control onto the WebForm. When you click the button some
text is displayed in a TextBox. The code for that looks like this:
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "Welcome to TextBoxes"
End Sub
|
Sample2, Multiline TextBox
Drag a TextBox, Button and a Label control onto the form. We will make this TextBox
a Multiline textbox and display the text entered in this multiline textbox on a label.
Before you proceed, select the textbox, open it's properties window and set it's TextMode property
to Multiline. The code to achieve the desired functionality
looks like this:
Private Sub Button2_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button2.Click
Label2.Text = TextBox2.Text
End Sub
|
Sample3, Password Character
Drag a Textbox, Button and a Label control onto the form. Select the textbox, open
it's properties window and set the TextMode property to Password.
When you set TextMode property to password, the text you enter in the textbox is masked
with asteriks (*). The following code displays the text you entered in the textbox
as text for the label.
Private Sub Button3_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button3.Click
Label3.Text = TextBox3.Text
End Sub
|
Live Code Demo
Sample1
Sample2
Sample3
|