Question
How do I initialize the contents of a password textfield in ASP.NET 2.0?
Simple anwser
You can’t! This doesn’t work (apparently this is for security reasons, although the exact motivation escapes me):
1 | txtPassword.Text = "this sucks" ; |
Better answer
Create an event handler for the TextBox’s PreRender event:
1 2 3 4 5 | protected void txtPassword_PreRender( object sender, EventArgs e) { TextBox txt = (TextBox)sender; txt.Attributes[ "value" ] = txt.Text; } |
Voilá! Now you can assign to the Text property as in the first example.
(Credits for this tip to David Silverlight.)