|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Respond to Changes in a TextBox Web Server Control
When the user leaves aWeb server control after entering information, the control raises an event that you can respond to.
The TextBox Web server control does not raise an event each time the user enters a keystroke, only when the user leaves the control. You can have the TextBox control raise client-side events that you handle in client script, which can be useful for responding to individual keystrokes. For details, see.
To respond to changes in the TextBox control
Create an event handler for the TextBox control'sevent.
By default, the TextChanged event does not immediately cause the Web Forms page to be posted to the server. Instead, the event is raised in server code the next time the form is posted. To have the TextChanged event cause an immediate posting, set the TextBox control'sproperty to true.
The following code example shows how you can respond to changes in the TextBox control. The code displays the contents of the control in a label.
User input in a Web Forms page can include potentially malicious client script. By default, the Web Forms page validates that user input does not include script or HTML elements. For more information, see.
Protected Sub TextBox1_TextChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles TextBox1.TextChanged Label1.Text = Server.HtmlEncode(TextBox1.Text) End Sub