The TextBox server control is an input control that lets the user enter text.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server">Hello</asp:TextBox>
Or
<asp:TextBox ID="TextBox1" runat="server" Text="Hello"></asp:TextBox>
You can also set the TextMode property to SingleLine MultiLine or Password. By default, the TextMode property is set to SingleLine, which creates a text box with only one line.
MultiLine creates a text box with more than one line.
Password creates a single-line text box that masks the value entered by the user.
Use the Max Length property to determine the contents of the TextBox control. You can limit the number of characters that can be entered in the control by setting the MaxLength property.
Here we set MaxLength 10, after 10 characters you will not be able to enter text in textbox
We can change textbox UI
<asp:TextBox ID="TextBox1" runat="server" Font-Bold="True" Font-Italic="True"
Font-Names="Arial" ForeColor="#FF33CC"></asp:TextBox>
TextBox Event:
Name | Description |
TextChanged | Occurs when the content of the text box changes between posts to the server. |
TextChanged event fire when you write any text in textbox
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Label ID="Label1" runat="server"></asp:Label>
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
Now execute the website
Write any text in textbox and click outside of the textbox then TextChanged event fire and written text will show in Label.
Leave Comment