views:

30

answers:

3

Hello,

If you have a page with an <asp:TextBox TextMode="Password" ... />.
How can you keep the value after a postback?

This is my problem:
At the registration screen of my app you need to enter a password. Then you click submit, a postback occurs and the password fields are cleared, how can I prevent the password field from clearing?

Cheers

+2  A: 

You require to set it again in page_load or in button click event like this :

 string Password = txtPassword.Text;
txtPassword.Attributes.Add("value", Password);
Pranay Rana
thx this works perfectly
Sem Dendoncker
+1  A: 

You need to set back the password to the textbox on postback.

txtBox.Attributes["value"] = txtBox.Text;
Krunal
+2  A: 

<input type="password" /> is treated differently than other form controls since it stores sensitive information that is a password of a user. At server side, for every postback the password textbox is force-fully cleared for this reason, should you really need to persist the value in password text-box, set it explicitly as others have mentioned here. But I really don't recommend doing so since it's not a good practice.

this. __curious_geek
the customer demands it.therefore I need to implement it.
Sem Dendoncker
right, in that case it's ok.
this. __curious_geek