?
Solved

Replace password in textbox after postback. HOW?

Posted on 2006-07-03
9
Medium Priority
?
445 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

862 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