Storing a password-mode TextBox value after postback

You know those annoying times when you fill out a large form, submit it, and a post back to the server is performed. But, horror of horrors, you made a mistake, and the page prompts you to make a correction, but the password (or credit card number or whatever) field was cleared! I hate that.

I had an instance where I was that annoyance, and it was keeping me up at night, tossing and turning, worrying what I could do to solve that issue. (That’s sarcasm right there, people.) So after a very brief bit of research, I found this code snippet to fix the problem:

txtPassword.Attributes.Add("value", txtPassword.Text);

Yes, that really is it. I just put that code at the end of my submit button’s click event.

Advertisements
  1. #1 by Sathish on July 12, 2011 - 6:45 am

    Thanks, i fixed my issue by ur answer. This is helpful for me to fix this issue, once again thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: