Here we will explain how to use text box in or what is text box in or how to get text box value when user click on button in with example.


The TextBox control is used to create a text box where the user can input text.

The example below demonstrates some of the attributes you may use with the TextBox control:

  • Example:
  • TextBoxDemo.aspx:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxDemo.aspx.cs" Inherits="AspDotNet.TextBoxDemo" %>


<!DOCTYPE html>


<html xmlns="">

<head runat="server">




    <form id="form1" runat="server">


    <table style="line-height: 28px;">


            <td colspan="2"><b>Singleline text box</b></td>




            <td>Name :</td>


                <asp:TextBox ID="txtname" TextMode="SingleLine" runat="server"></asp:TextBox>





            <td colspan="2"><b>Multiline textbox</b> </td>




            <td style="vertical-align:top;">Address:</td>

            <td> <asp:TextBox ID="txtaddress" TextMode="MultiLine" runat="server"></asp:TextBox></td>



            <td colspan="2" style="text-align:right;">

                <asp:Button ID="Show" runat="server" Text="Show" OnClick="Show_Click" /></td>




            <td>Your Name :</td>


                <asp:Label ID="lblname" runat="server" Text="Label"></asp:Label>  





            <td>Your Address :</td>


                <asp:Label ID="lbladdress" runat="server" Text="Label"></asp:Label> 












using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace AspDotNet


    public partial class TextBoxDemo : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)





        protected void Show_Click(object sender, EventArgs e)


            lblname.Text = txtname.Text;

            lbladdress.Text = txtaddress.Text;





In Above example when user Enter Name and Address and click on show button then your entered name and Address show in below.

Let’s see Output:

How to use TextBox Control in Asp.Net

  • The TextBox control's attributes and properties are listed below:
  • Property



    Specifies the AutoComplete behavior of a TextBox


    A Boolean value that specifies whether the control is automatically posted back to the server when the contents change or not. Default is false


    Specifies if a page is validated when a Postback occurs


    The width of the textbox


    The maximum number of characters allowed in the textbox


    Specifies whether or not the text in the text box can be changed


    The height of the textbox (only used if TextMode="Multiline")


    Specifies that the control is a server control.  Must be set to "server"




    The contents of the textbox


    Specifies the behavior mode of a TextBox control (SingleLine, MultiLine or Password)


    The group of controls that is validated when a Postback occurs


    A Boolean value that indicates whether the contents of the textbox should wrap or not


    The name of the function to be executed when the text in the textbox has changed

I hope this will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like