Solved

Replace password in textbox after postback. HOW?

Posted on 2006-07-03
9
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

732 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