views:

663

answers:

3

Hi all, I have problem with password text box control. I have username textbox, password textbox, retypepassword textbox. And i have drowpdownlist with items Website, Newspaper, Others. After filling username, password, retype password in textbox. Whenever i am selecting items Newspaper and Others items from drowdownlist, password and retypepassword textbox value getting cleared. I have set in autopostback=true in dropdownlist control. Pls somebody help me where is my mistake??

Thanks, Sumit

+3  A: 

It's not a mistake it's just that passwords won't be sent back to the client after a postback, this is by design. What is your intent?.. is there a reason you would like the password boxes to persist through postbacks?

Quintin Robinson
I have set autopostback=true in dropdownlist not in password text box control. My intention is when i am selecting any value from dropdownlist password and retypepassword value should not be cleared, it should be remained same with filled values until i click save button. Pls tell me how do i achieve it???
Sumit
Well you could use the approach recommended by harpo but beware that this will expose the password back in plaintext in the rendered HTML. Alternatively you could wait to ask for password input until the rest of the content that requires postbacks has been completed or stop posting back on the dropdownlist if not required.
Quintin Robinson
I agree. Try to adhere to the philosophy of what a password field is. It should not be persisted, and this is the typical design of most sites. Ever signed up for an account that requires creating a username and password, and upon form submition you get a message indicating some information is missing. Guess what happens to that 'password' field you already filled out? It is empty again. This is the best way to approach this by not trying to break the design.
atconway
+3  A: 

As Quintin indicated, this is by design. TextBox.Text does not get persisted when TextMode is "Password". You can work around this by setting

txtPassword.Attributes[ "value" ] = txtPassword.Text;

some time during page processing.

harpo
+1  A: 

You can put the DropDownList onto an UpdatePanel. Or use JavaScript instead of server side postback.

Mehdi Golchin
When i am keeping the DropDownList onto an UpdatePanel, Other textbox is not appearing. If i select Others items from dropdownlist Others textbox has to appear.
Sumit
I can't realize what you mean? But if you mean the Textboxes doesn't show when you select an item from DropDownList, note that you should put them in UpdatePanel as well.
Mehdi Golchin