Solved

Replace password in textbox after postback. HOW?

Posted on 2006-07-03
9
437 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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