Password Fields Lose Value During PostBack

N

Nathan Sokalski

I have a form, and when the form does a PostBack (I have several areas on
the form where the form changes if the user selects a different
RadioButton), the Password field is cleared, even though I have
EnableViewState set to True. None of the other TextBoxes lose their value. I
also tried using Session variables to store the value between postbacks, but
I must be doing this in the wrong event, because it does not seem to be
having an effect. What can I do to prevent the Password field from losing
it's value? Thanks.
 
M

Marina

This is a security feature. So the password isn't sent down to the browser
in clear text.

The ViewState is just an encrypted version of what was last sent down, so
that next time there is a post to the server, it can all be sent back up as
one thing. It can then be used on the server, to see if a field's value
changed, etc.

The browser does not care about ViewState, and does not use it to populate
its controls.

There is no way to override the behavior. The only way you can do this, is
to do it in javascript, but that would most likely mean sending the password
down in clear text, where anyone who knows how to do View -> Source can look
at it.
 
S

Steve C. Orr [MVP, MCSD]

This is the default behavior. It minimizes passwords being transmitted
around the internet any more than they have to be. It's a security
precaution.

There is a workaround if you're determined. You can set the password text
via client side script.
Here's the simplest example I've seen:

MyPWTextBox.Attributes.Add("value", strPassword)

This server side code outputs the needed client side code to fill in the
password. For reasons mentioned earlier, it's preferable to avoid
transmitting the password around like this when possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top