USE OF TEXT BOX CONTROL IN ASP.NET
A TextBox control is a rectangle box that is used to take user input. In simple words, a TextBox is a place where users can input some text on an asp.net webform. TextBox Control is the most useful web server control in ASP.NET. To create a TextBox we can either write code or use the drag and drop feature of the Visual Studio IDE.
Syntax of ASP.Net TextBox
<asp:TextBoxID=”TextBox1”runat=”server”></asp:TextBox>{codeBox}
The server presents it as an HTML control and provides the following code for the browser.
<input name=”TextBox1″ id=”TextBox1″ type=”text”>{codeBox}
Text Box Properties
All server-side controls have their own properties and events. The list below shows the TextBox properties.
Set Properties? (How to set properties?)
In ASP.Net we can set the properties in two ways.
Design Time - When you are developing, designing, or coding, where does it go Design Time?
Run time - When you run coding, it is called Run Time.
Example –
- TextBox1.Backcolor=System.Drawing.Color.Yellow;
- TextBox1.BorderStyle=BorderStyle.Solid;
- TextBox1.BorderColor=System.Drawing.Color.Red;
- TextBox1.BorderWidth=3;
- TextBox1.ForeColor=System.Drawing.Color.Green;
- TextBox1.Font.Bold=True;
- TextBox1.MaxLength=10;
- TextBox1.TextMode=TextBox.Password;
Methods
There are three things in every control.
- Properties
- Methods
- Events
2. TextBox Methods
Focus - To set the cursor on a textbox.
ToString - To convert Textbox content to a string.
3. TextBox Events
Only exchange is used in the event. This happens when we change the value.
How to use TextBox in ASP.Net
Step 1 - Open Visual Studio -> Create a new blank web application.
Step 2 - Create a new web page for the textbox example.
Step 3 - Drag and drop the textbox control on the web page from the toolbox.
Step 4 - Set the ID property of the control - eg: text name, toxicity, tx mobile
Step 5 - Use the Text property used to control the text or get the text from the control.