Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Generally we have textbox Textmode as password.

Similarlly I want label Textmode as password format


Is there any way please help me


Thanks in Advance.
Posted
Updated 28-Apr-16 4:44am
v4
Comments
Mohd Wasif 27-Jul-11 3:06am    
Please clarify your question.
Praveen Kullu 27-Jul-11 3:14am    
"enter Password format"? Do you want to change the label text at runtime?

I dont know why you would want this?? Anyway, create new User Control and add a label on it, then, in the code behind add a Text property:

C#
private string _text = string.empty;
public string Text
{
    get
    {
        return _text;
    }
    set
    {
        _text = value;
        lblMyLabel.Text = "";
        foreach(char c in value)
            lblMyLabel.Text += "*";
    }
}


Then you just add that user control to your page I guess! Thats if I am understanding your question.
 
Share this answer
 
v2
Comments
kranthi.oru 27-Jul-11 3:57am    
Thank you very much for your coparation.
Why would you want a password format label? The user can't enter it, he can't read it, but is would be completely insecure since a right click and "view source" would show the password as clear text to anyone who wanted to use it.

I noticed you want it "like a textbox" so it isn't for user input - what are you trying to achieve that you think this will solve your problem? There may be a better way to do that.
 
Share this answer
 
Comments
DominicZA 27-Jul-11 4:38am    
I agree with you totally. However, if he just wants to show how many characters there are int the password(again, this is stupid), the above method will work and is secure.
If you are planning to show password of textbox to label using UseSystemPassword = true, then it can be retrieved very easily just as OrginalGriff said above.

unless you do this: though i am not sure how much secure is it

C#
foreach(char ch in textBox1.Text.ToCharArray())
{
label1.Text += "*";
}


<br />
Done using VS2005
 
Share this answer
 
v3

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