Latest web development tutorials

ASP.NET TextBox control

TextBox control is used to create a user can enter text in the text box.


TextBox controls

TextBox control is used to create a user can enter text in the text box.

Characteristics and attributes of a column in the TextBox control our WebForms Controls reference page .

The following example demonstrates that you may use some of the attributes of the TextBox control:

Examples

<html>
<body>

<form runat="server">

A basic TextBox:
<asp:TextBox id="tb1" runat="server" />
<br /><br />

A password TextBox:
<asp:TextBox id="tb2" TextMode="password" runat="server" />
<br /><br />

A TextBox with text:
<asp:TextBox id="tb4" Text="Hello World!" runat="server" />
<br /><br />

A multiline TextBox:
<asp:TextBox id="tb3" TextMode="multiline" runat="server" />
<br /><br />

A TextBox with height:
<asp:TextBox id="tb6" rows="5" TextMode="multiline"
runat="server" />
<br /><br />

A TextBox with width:
<asp:TextBox id="tb5" columns="30" runat="server" />

</form>

</body>
</html>

The demonstration >>

Adding a script

When the form is submitted, TextBox control content and settings may be modified server scripts. Form by clicking a button or when a user modifies the value of a TextBox control when to commit.

In the following example, we declare a TextBox control in an .aspx file, a Button control and a Label control. When the submit button is triggered, submit subroutine will be executed. submit subroutine writes a line of text to the Label control:

Examples

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

The demonstration >>

In the following example, we declare a TextBox control and a Label control in an .aspx file. When you modify the values ​​in the TextBox and click outside the TextBox (or press the Tab key), change the subroutine will be executed. change subroutine will write a line of text to the Label control:

Examples

<script runat="server">
Sub change(sender As Object, e As EventArgs)
lbl1.Text="You changed text to " & txt1.Text
End Sub
</script>

<html>
<body>

<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server"
text="Hello World!"
ontextchanged="change" autopostback="true"/>
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

The demonstration >>