Share via


How to: Get and Set Values in TextBox Web Server Controls

You can get or set the value of a TextBox control at run time.

Security noteSecurity Note

User input in a Web 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 How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings.

To get or set values in the TextBox control

  • Get or set the value of the control's Text property.

    The following code example shows how you can read the value of one TextBox control called TextBox1 and use it to set the value of another, TextBox2.

    Protected Sub Button1_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
       Textbox2.Text = Server.HtmlEncode(TextBox1.Text)
    End Sub
    
    protected void Button1_Click(object sender, System.EventArgs e)
    {
       TextBox2.Text = Server.HtmlEncode(TextBox1.Text);
    }
    

See Also

Reference

TextBox Web Server Control Overview