Partager via


How to: Set a TextBox Web Server Control for Password Entry

A TextBox Web server control set for passwords hides a user's entry as it is being typed. Password text boxes can only be single-line text boxes.

Security noteSecurity Note

Using a TextBox control set for passwords can help ensure that other people will not be able to determine a user's password if they observe the user entering it. However, the password text entered is not encrypted in any way, and you should protect it as you would any other confidential data. For example, for maximum security when posting a form with a password in it, you might use Secure Sockets Layer (SSL) and encryption.

To create a password text box

  1. Set the TextBox control's TextMode property to Password. In code, text modes are set using the TextBoxMode enumeration.

  2. Set the size of the control by setting its Width property to a value in pixels or its Columns property to the number of characters to display. If you set both properties, Width takes precedence.

    Note

    The Width property does not work in browsers that do not support cascading style sheet (CSS) styles.

  3. Optionally, you can limit the number of characters the user is allowed to enter by setting the control's MaxLength property. If a user exceeds this number of characters, the control stops accepting more.

    Note

    You might not want to set the MaxLength property, because it can be of use to unauthorized users who are trying to guess the password.

See Also

Reference

TextBox Web Server Control Overview