Solved

Replace password in textbox after postback. HOW?

Posted on 2006-07-03
9
438 Views
Last Modified: 2012-08-13
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?

0
Comment
Question by:volking
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17033755
for security reasons you cant populate a password box
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17033760
This is a security feature.

Bob
0
 
LVL 23

Expert Comment

by:apresto
ID: 17033761
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?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:volking
ID: 17033800
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.
0
 
LVL 5

Author Comment

by:volking
ID: 17033832
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.
0
 
LVL 4

Expert Comment

by:Jigit
ID: 17034028
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
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 17035744
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
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 17035762
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);

            }
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 17035781
I think this solution may suitable for u.
TextBox1.Text is the text box with password mode.
TextBox2.Text is the normal ,single line text box
private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  if(Page.IsPostBack)
                  {
                         Session["Password"]=TextBox1.Text;
                  }
      
            }



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

            }


Regards
Pradeep
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question