An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

Assigning the text value for a Password Textbox

Monday, April 25, 2005 7:45 AM
Hi,

Setting the text property for a textbox with textmode=single and multiline is pretty straight forward by giving

TextBox1.Text = "The text we want to set";

However, if we set the Textmode property to Password, then we cannot simply set the text using the TextBox.text.

In practical scenarios, we may not want to set the password for obvious reasons that password is one which we retrieve from the user and it shoult not be set.

Also, even if we set some password, the user cannot read it as it is just a sequence of dots.

If, for however, due to specific reasons, we need to set the password, then we can do the same by using the following code:-

txtpasswd.Attributes.Add("value", "the password we wish to set");

Or, if you are assigning the password from the database you can use a DataReader in place of the actual password, as follows :

txtpasswd.Attributes.Add("value", objRdr["Password"].ToString());

Cheers.

Feedback

# re: Assigning the text value for a Password Textbox

How does this work on a mobile textbox? 12/3/2005 12:07 PM | RDS

# re: Assigning the text value for a Password Textbox

Thank you. I was banging my head against the wall trying to figure out why it wasn't getting set with just a txtpass.Text = "Password"; 12/19/2005 2:25 PM | Ralph Whitbeck

# re: Assigning the text value for a Password Textbox

Thanks a lot, this solution is very much useful. 1/16/2006 5:58 AM | Anandaraman

# re: Assigning the text value for a Password Textbox

thank you for help. it was very useful for me. 4/4/2007 9:55 AM | omarir

# re: Assigning the text value for a Password Textbox

How manay scienirio of the password text box
?
09998772434 5/12/2008 8:07 PM | lokesh Thakre

Post a comment





 

Please add 2 and 2 and type the answer here: