TextBox Control
Asp.net TextBox Web Control:
The TextBox control in asp.net is use to create a user input box
in which user can give any type of text input .This is predefine input type
control which have some properties and methods.
Textbox in Asp.net
Text box is an asp.net web control, use for getting input by user as like
in the login web page we see username and password Textbox where we enter
username and password.
In the Toolbox we get a textbox simply drag and drop it on asp.net web page
then it is automatically create our html code.The example is given here with some of the attributes of TextBox control.
Textbox control in asp.net |
Declare A Textbox :
<html>
<body>
<form runat="server">
//A basic TextBox:
<asp:TextBox id="txtusername" runat="server" />
<br /><br />
//A password TextBox:
<asp:TextBox id="txtpassword" TextMode="password" runat="server" />
<body>
<form runat="server">
//A basic TextBox:
<asp:TextBox id="txtusername" runat="server" />
<br /><br />
//A password TextBox:
<asp:TextBox id="txtpassword" TextMode="password" runat="server" />
<br /><br />
</body>
</form>
</html>
Here in this Example we take two Textbox with their id first
is txtusername for take input User Name and second txtpassword for password field
.Both has runat=”server” attribute. Means these Textbox run at server end.
Asp TextBox with text Property:
<asp:TextBox id="Txtbox1" Text="Hello World!" runat="server" />Multiline TextBox control:
<asp:TextBox id="Txtbox2" TextMode="multiline" runat="server" />Asp net custom textbox with height and width:
<asp:TextBox id="Txtbox3" width=”100px” Height=”100px” runat="server" />Asp net textbox properties
Access key,
AutoCompleteType, AutopostBack, BackColor, BorderColor,BorderStyle,BorderWidth,CausesValidation,Font,Height,Width,ReadOnly,Row,Text,TabIndex
etc.
C# programming Script for Text control
The Text and property of a TextBox control may be changed by server scripts when a form is submitted. As we know that when we clicked on button or when a user change value in the TextBox control.In the following example we declare a asp.net TextBox control, one asp.net Buttoncontrol, and one asp.net Label control in an .aspx file. When the submit button then the text of Textbox will change
Example of Asp.net textbox:
Code on .aspx page :
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="TextboxExample.aspx.cs"
Inherits="TextboxExample"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1"
runat="server"
Text="This is text
box."
Font-Bold="True"
Font-Size="X-Large"
Height="73px"
Width="550px"></asp:TextBox>
<br />
<asp:Button ID="Button1"
runat="server"
Text="Button"
Height="51px"
onclick="Button1_Click"
Width="339px"
/>
<br />
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Code on aspx.cs page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TextboxExample
: System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
TextBox1.Text = "welcome to text box
Example";
}
}