Assigning the text value for a Password Textbox

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.

Print | posted on Monday, April 25, 2005 7:45 AM

Comments on this post

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
How does this work on a mobile textbox?
Left by RDS on Dec 03, 2005 12:07 PM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
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";
Left by Ralph Whitbeck on Dec 19, 2005 2:25 PM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
Thanks a lot, this solution is very much useful.
Left by Anandaraman on Jan 16, 2006 5:58 AM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
thank you for help. it was very useful for me.
Left by omarir on Apr 04, 2007 9:55 AM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
How manay scienirio of the password text box
?
09998772434
Left by lokesh Thakre on May 12, 2008 8:07 PM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
Thanks a lot for the help n_n
Left by Zeroark on Jun 11, 2009 8:10 PM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
it was very useful for me.
Left by mario oyunları on Sep 21, 2009 10:47 AM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
Thanx alot.. was very useful.
Left by dran on May 30, 2010 10:11 PM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
Exactly what i looking for..Thanks
Left by Nedir on Nov 03, 2010 5:16 AM

# re: Assigning the text value for a Password Textbox

Requesting Gravatar...
Hi,
txtpasswd.Attributes.Add("value", "the password we wish to set");
where i have to place this code whether in javascript or what...?
Left by swathi on May 05, 2011 9:19 AM

Your comment:

 (will show your gravatar)