Thursday, April 15, 2010

ASP.NET C# Set Value to Password Textbox in Code Behind

If ever you've tried setting value in code-behind to a textbox with TextMode property set to "Password", you would notice it doesn't display the masked text on the page. This is simply the way it is for security purposes, but there is a workaround so you can show the user there is actually text in the textbox.


Here is the snippet:


txt1.Text = "sample_password";


if (txt1.TextMode == TextBoxMode.Password) 
{
    txt1.Attributes.Add("value", txt1.Text);
}


Just set the same text value to the javascript attribute "value" and you're done.

4 comments:

  1. Really nice information you had mentioned here. Thank you for opening the opportunity to know more with the employment details. So please keep update like this.

    Recruitment Consultancy in Chennai

    ReplyDelete
  2. I really appreciate your proficient approach. These Measure area unit of measurement unit things of really useful knowledge which is able to be of nice use on behalf of me in future.

    ReplyDelete