about learning and improving skills
Pre-fill password fields in ASP.NET
At some stage I had to pre-fill a password field. Actually that is something you don’t want to do because the value can be seen in the plain html text. But perhaps you want to show some **** initially on a new user page or something.
ASP.NET won’t render the value of a TextBox with textmode set to password into the page, but you can force the required html to pre-fill password fields using the .AddAttribute(“value”, password); method on the control:
TextBox passwd = new TextBox() { TextMode = TextBoxMode.Password }; passwd.AddAttribute("value", "*****");
I already mentioned you can see the password in plain text in the html, so it is a bad idea to do that with real passwords. You should try to avoid this. But in some cases (i.e. display password strength / weakness during initial password entry on a “new user” page, with no real password but a dummy value) this totally makes sense.
| Print article | This entry was posted by Sebastian on 2010/07/23 at 18:50, and is filed under ASP.NET, Development. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |