TextBox Control in ASP.Net

In previous asp.net server control post we had discussed about MultiView Control and ListBox Control and FileUpload Control and CheckBox Control and RadioButton Control and DropDownList Control and Adrotator Control.

ASP.Net TextBox Control

Textbox control is a most usable web server control in asp.net.
TextBox control is a rectangular box which is allow user to input some text value. If we want to get some text from users then we have to use textbox control in asp.net.In simple word the textbox control is a place where user can input some text on asp.net web page.

 

How to use TextBox control in ASP.Net C#

To understand more about asp.net textbox control let’s take an example.

First create new asp.net web application with a default.aspx web forms.

Drag and drop the textbox control from toolbox to web page.

ASP.Net TextBox control

ASP.Net TextBox control

We can get the content of textbox control using Text property. Text property is used to get text displaying in textbox control.

Here is the syntax of Text property of textbox control.

ASP.Net TextBox control

ASP.Net TextBox control

Properties of TextBox Control

ID – ID is the identification name of textbox control.
Text - Display text in the textbox control.
BackColor - Set the background color of textbox control.
CssClass  - stylename (used to apply style on textbox control.)
Enable - true/false (used to enable and disable control.)
Enable Theming - true/false (used to enable and disable effect of theme on textbox control)
Visible - true/false (used to hide or visible control on web page)
CausesValidation – true/false (used to enable and disable validation control effect on textbox control)
ToolTip – Display the text on control when mouse over on textbox control.
TabIndex – manage the order of tab.

Here are some important properties of TextBoxControl

MaxLength - used to define the length of character in textbox.
ReadOnly - true/false (Readonly property used to enable/disable modification of text)
TextMode - Single / Multiline / Password

ASP.Net TextBox Example

write a text in textbox control programmatically on button click event in asp.net.

write below C# code on button click event at code behind page.

ASP.Net TextBox control

ASP.Net TextBox control

Now, for understand other property of textbox, check the below asp.net textbox example.

Here is the html design source code of textbox example :

Below screen is a out put of design of textbox control example.

ASP.Net TextBox Control Example

ASP.Net TextBox Control Example

TextBox MexLength

TextBox1.MaxLength - MexLength property used to set character length inputted by user. In MexLength we can set any integer value, if we set textbox mexlength = 5 then we can only input 5 character in textbox when run the asp.net website.

In below textbox mexlength example we set mexlength property = 8, so we can input only 8 character in textbox shows like below figure.

Here is code for set mexlength property programmatically in asp.net.

TextBox MexLength  - ASP.Net

TextBox MexLength – ASP.Net

TextBox ReadOnly

TextBox ReadOnly property used to enable or disable modification of text in textbox control in asp.net.

Here, we set Boolean value true or false for textbox readonly. If textbox readonly=true then we can only read the content of textbox, we can’t edit or modifying text content of textbox.

In below example we set textbox ReadOnly = true

TextBox ReadOnly - ASP.Net

TextBox ReadOnly – ASP.Net

TexBox Background Color

Textbox BackColor - The BackColor is used to change the background color of textbox control.

Textbox BackColor - ASP.Net

Textbox BackColor – ASP.Net

TextBox Border Style

Textbox border - If we make a border of textbox control, then we need to set textbox borderstyle, textbox borderwidth and textbox bordercolor.

TextBox Border - ASP.Net

TextBox Border – ASP.Net

TextBox Password Mode

TextBox Password Mode - If we set textbox textmode equal to password mode, then the inputted text will be converted to password (*) character.

TextBox Password Mode - ASP.Net

TextBox Password Mode – ASP.Net

TextBox SingleLine Mode

The basic by default mode of textbox is single line. The normal textbox is single line textbox.

TextBox SingleLine Mode - ASP.Net

TextBox SingleLine Mode – ASP.Net

TextBox Font Color

Textbox ForeColor property is used to change the text color of textbox.

TextBox Font Color - ASP.Net

TextBox Font Color – ASP.Net

TextBox Bold Font

The Textbox font bold is used to display bold font text in textbox.

TextBox Width - ASP.Net

TextBox Width – ASP.Net

TextBox Width

TextBox Width - ASP.Net

TextBox Width – ASP.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 5 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">