Setting Value in Textbox with TextMode=”Password”

February 22, 2009

Recently,

I had a requirement, that when user details are edited the admin should be able to edit the password.

First I should to display clear password (ofcourse it is worng) as that page was visible to admin only.

Then I had to change that and had to display asterik (‘*’) instead of clear password.

So Obvisiouly I did something like

18 this.txtPassword.Text = (string)dr[0];

But this did not work for me

So I googled and found this article

Setting Value of Password Field

so I just changed the above code to

18 this.txtPassword.Attributes.Add(“value”,(string)dr[0]);

and it worked liked a charm.

Note: Please do read this article, if you want to preserve the value for password field even when postback occurs.

That’s all folks.
Hope you enjoyed this post.

Comments Good as well as Bad are most welcome.

NJoy !!! 🙂

Advertisements