Controls You Can Use on Web Forms ASP.NET Standard Controls TextBox Control
You can get or set the value of a TextBox control at run time.
- Get or set the value of the control’s Text property.
The following example shows how you can read the value of a TextBox control and use it to set the value of another control, in this case, a Label control.
In this case, the method simply handles a Button control’s Click event and displays in the Label whatever the user has typed into the TextBox.
void setLabelText ( object src, EventArgs e ) {
msg.Text = myTextBox.Text;
}
Sub setLabelText ( ByVal sender as Object, ByVal e as EventArgs )
msg.Text = myTextBox.Text
End Sub |
|
C# |
VB |
NOTE: 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. In addition, authors can apply HTML encoding to strings to protect against script exploits in a Web application.
private void myTextHandler ( object src, EventArgs e ) {
...
msg.Text = Server.HtmlEncode ( myTextBox.Text );
}
Private Sub myTextHandler ( ByVal src As Object, ByVal e As EventArgs )
...
msg.Text = Server.HtmlEncode ( myTextBox.Text )
End Sub |
|
C# |
VB |
Web Forms Events and Handlers Setting Web Server Control Properties Programmatically