Monday, 3 October 2011

Assign Value to Asp.Net TextBox with mode=”Password”

 Using ASP.NET, the default textbox in password mode (TextMode="Password") has the following restrictions:

  • The password can not be set (e.g., tbPassword.Text = "ThePassword";)
  • The password is not restored after a postback
Both restrictions make perfect sense for security reasons. Nonetheless, sometimes the above behaviour is not wanted (especially during development).
The new PasswordTextBox control is an extension of the standard ASP.NET TextBox and makes a password textbox behave like a regular textbox.

PasswordTextbox.Attributes.Add("value", "ThePassword");

Use this to set the value, instead of setting the Text Property.

No comments:

Post a Comment