Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a textbox named passwordtextbox which has the passwordchar property of * to hide passwords. I also have a button named show to show passwords hidden by the passwordchar.Please i need help on how to go about it in c#?
Posted
Updated 19-Jan-23 23:10pm
Comments
King Fisher 29-Apr-14 4:03am    
What have you tried?
MaximusDebois 29-Apr-14 4:06am    
this.password.passwordchar='';

Set PasswordChar to \0...
this.password.passwordchar='\0';
 
Share this answer
 
Comments
george4986 29-Apr-14 4:29am    
working code +5v
Kornfeld Eliyahu Peter 29-Apr-14 4:31am    
Thank you...
Try this to show password:
C#
passwordtextbox.PasswordChar = char.MinValue;


I suggest to replace the show button with checkBox and:
C#
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
   this.passwordtextbox.PasswordChar = this.checkBox1.Checked ? char.MinValue : '*';
}
 
Share this answer
 
v3
For web application use code given below

C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
TextBox1.TextMode = (CheckBox1.Checked ? TextBoxMode.SingleLine : TextBoxMode.Password);
}



For windows application use code given below

C#
 private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
textBox1.PasswordChar = (checkBox1.Checked ? char.MinValue : '*');
}
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 29-Apr-14 5:39am    
OP definitely talk about WinForms application - see his comment with code sample...
Alos you web solution is not too user friendly! Every time user want to see the password you force him to post back to the server - this costs a bit too much...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900