Introduction:

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

Description:

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="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

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

    <div>

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

        <tr>

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

            

        </tr>

        <tr>

            <td>Name :</td>

            <td>

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

 

            </td>

        </tr>

        <tr>

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

           

        </tr>

        <tr>

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

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

        </tr>

        <tr>

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

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

            

        </tr>

       <tr>

            <td>Your Name :</td>

            <td>

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

 

            </td>

        </tr>

        <tr>

            <td>Your Address :</td>

            <td>

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

 

            </td>

        </tr>

    </table>

    </div>

    </form>

</body>

</html>

 

 

TextBoxDemo.aspx.cs

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

    Description

    AutoCompleteType

    Specifies the AutoComplete behavior of a TextBox

    AutoPostBack

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

    CausesValidation

    Specifies if a page is validated when a Postback occurs

    Columns

    The width of the textbox

    MaxLength

    The maximum number of characters allowed in the textbox

    ReadOnly

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

    Rows

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

    runat

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

    TagKey

     

    Text

    The contents of the textbox

    TextMode

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

    ValidationGroup

    The group of controls that is validated when a Postback occurs

    Wrap

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

    OnTextChanged

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

I hope this will help to you.

0 comments


Leave a comment

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

you may also like