Textbox Control in Asp.Net

In Asp.Net, the TextBox server control serves as a versatile input control, designed to accept user input within web applications. By default, TextBoxes are configured to accommodate a single line of text, providing a simple yet effective means for users to provide their input. However, it is important to note that the flexibility of the TextBox control extends beyond its default behavior, enabling developers to enhance user experience by utilizing advanced features.

Multiline text input

One notable capability of the TextBox control is its ability to support multiline text input. By altering the value of the TextMode property to TextBoxMode.MultiLine, developers can effortlessly transform a TextBox into a more expansive and accommodating text box, capable of accepting multiple lines of input. This empowers users to express themselves more comprehensively, particularly in scenarios where longer textual content or structured input is required.

textbox-control

Another valuable feature of the TextBox control is its capacity to mask user input. By modifying the TextMode property to TextBoxMode.Password, developers can use the TextBox control to create password fields, ensuring that sensitive information remains hidden from prying eyes. This essential functionality enhances security and confidentiality, safeguarding user credentials and other sensitive data.

VB.Net
TextBox1.TextMode = TextBoxMode.MultiLine
C#
TextBox1.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine;

If you want to limit the user input to a specified number of characters, set the MaxLength property.

VB.Net
TextBox1.MaxLength = 5
C#
TextBox1.MaxLength = 5;

The following ASP.NET program retrieve user input from a TextBox control and display it to a Label control.

Defaul.aspx
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>   <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>
Full Source | C#
using System; public partial class _Default : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "You entered : " + TextBox1.Text; } }
Full Source | VB.NET
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = "You entered : " & TextBox1.Text End Sub End Class