Link to home
Start Free TrialLog in
Avatar of volking
volking

asked on

Replace password in textbox after postback. HOW?

I've got System.Web.UI.WebControls.TextBox with TextMode set to Password. When a postback occurs and something ELSE is wrong on the form, the password field is AUTOMATICALLY ERASED. I find this BAD! The user fixes the OTHER problem then re-submits the form, but now THE PASSWORD IS MISSING!

How do I repopulate a TextBox (with TextMode=Password) with a Password on a form postback?

Avatar of apresto
apresto
Flag of Italy image

for security reasons you cant populate a password box
Avatar of Bob Learned
This is a security feature.

Bob
I dont think its something that you can get around - have you seen any website any where on the web that does what you are asking?
Avatar of volking
volking

ASKER

I've already done it using JavaScript ... but I just didn't want to rely on JavaScript ... I had hopes a "cleaner-way" existed, thus my EE question.
Avatar of volking

ASKER

I also guess this is why some websites have taken to a single (non-password clear-text) field when openning a new user account. The double-entry into two (password hidden) fields is probably better, but a mistake anywhere else on the form ..... can be painful (and confusing) for a user.
You can define your own control MyPasswordTextBox that inherits from the regular TextBox and take care of the value there. You can leave the value as is and just take care of replacing typed characters with asteriks.

HTH,
Jigit
Hi,
plz try like this

private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  if(Page.IsPostBack)
                  {
                         Session["Password"]=TextPasswordBox1.Text;
                  }
                  

            }


private void Button1_Click(object sender, System.EventArgs e)
            {
                  Response.Write(TextPasswordBox1.Text);
                  TextPasswordBox1.Attributes.Add("value",  Session["Password"].ToString());
                  Response.Write(TextBox2.Text);

            }


regards
pradeep
You can simply do like this also
private void Button1_Click(object sender, System.EventArgs e)
            {
                  Response.Write(TextBox1.Text);
                  TextBox1.Attributes.Add("value", TextBox1.Text);
                  Response.Write(TextBox2.Text);

            }
ASKER CERTIFIED SOLUTION
Avatar of pradeepsudharsan
pradeepsudharsan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial