Tuesday, January 13, 2009

Setting Text into ASP.Net Password TextBox

In the normal case if you set any value to Text property of TextBox which is in Password mode it won't get displayed.

textBoxPass.TextMode = TextBoxMode.Password;
textBoxPass.Text = "mypassword"; //This won't work

Here is one method to assign text into TextBox in password mode.

This make use of the attributes collection to set the value.

textBoxPass.TextMode = TextBoxMode.Password;
textBoxPass.Attributes.Add("value", "mypassword");
 

No comments: