1. aspnet-textbox

TextBox - (ASP.NET Web Forms)


A TextBox is a standard input control in the ASP.NET framework which allows a user to input text. It is an HTML <input> element with the type attribute set to text. The TextBox control has many useful properties and events, which makes it a popular choice for web developers building forms and collecting user input.


The basic syntax of a TextBox control is as follows:

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

The ID property value is used to reference the control in the code-behind and must be unique within the page.


Here's an example of how to use a TextBox control in an ASP.NET Web Form page:

<asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

In the code-behind, you can access the text entered into the TextBox control using the Text property. For example:

string name = txtName.Text;


The output of a TextBox control is a text input field where a user can enter text.


The TextBox control allows users to input text on an ASP.NET web page, and the text is sent back to the web server on post back. You can customize the appearance of a TextBox control using properties like ForeColor, BackColor, and Width. You can also set the ReadOnly property to true to prevent the user from editing the value of the TextBox control.


The TextBox control is commonly used in web forms to collect user input, such as names, addresses, or other types of information.

Important Points

  • The Text property of a TextBox control is used to access the value entered by the user.
  • The HTML maxlength attribute can be used to limit the length of the text that the user can input.
  • The TextBox control can be styled using properties like ForeColor, BackColor, and Width.
  • The TextBox control can be set to ReadOnly to prevent the user from editing its value.


In this page, we discussed the TextBox control in ASP.NET Web Forms. We covered the syntax, example, output, explanation, use, important points, and summary of the control. As a widely used input control, TextBox has many useful features and is a valuable addition to any web developer's toolbox.

Published on: