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.

12 comments:

  1. Wow! very nice information. i was searching article like this.

    Thanks

    http://mlmdevelopers.com/products/mlm-software/mlm-software-beta/features.html

    ReplyDelete
  2. Nice Blog.
    First Telugu contains telugu political news, latest news in telugu, telugu film news, Tollywood news, ap news, telangana news, movie trailers and movie reviews.

    ReplyDelete
  3. korada provides telugu political news and telugu movie news accurately. You can get genuine telugu political, cinema news current affairs, andhra news, telangana news and all latest news @ korada.com

    ReplyDelete
  4. Nice Post.
    Papajobs provides information about today walkins, it jobs, job notifications

    ReplyDelete
  5. Great Article. i read every post in this blog.
    Find Daily GK Updates, Government Jobs, bank recruitment.

    ReplyDelete
  6. Nice Post.
    indiaregisters provides domain registration, domain registration in india,cheap domain registration, domain registration in hyderabad.

    ReplyDelete
  7. 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
  8. 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
  9. MD.Shameem Mridha
    Looking great work dear, I really appreciated to you on this quality work. Nice post!! these tips may help me for future.

    ReplyDelete