Sumit
Sumit

Reputation: 23

Need help in asp.net password textbox

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

Upvotes: 0

Views: 3818

Answers (4)

JOJO
JOJO

Reputation: 316

In the dropdown_SelectedIndexChanged(object sender, EventArgs e) method set the password field and confirmpassword field

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

And again in the submit button click you have to clear the password field like the below

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

Upvotes: 0

m3kh
m3kh

Reputation: 7941

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

Upvotes: 1

harpo
harpo

Reputation: 43168

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.

Upvotes: 6

Quintin Robinson
Quintin Robinson

Reputation: 82325

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?

Upvotes: 4

Related Questions