i am doing a project in class that you have to type in a password and have the password given back to you with astrixs which i did but the second part is i have to write an event handler that repeats the password back without the astriks here is my code so far

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

        protected void TxtPassword_TextChanged(object sender, EventArgs e)
    {

    }
}

i forget what i have to put in the txt password field to get it to display i already put a label in can u help me with the next step please?

<form id="form1" runat="server">
    <div>
 
        <asp:TextBox ID="TxtPassword" runat="server" 
            TextMode="Password" ontextchanged="TxtPassword_TextChanged"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text="Password"></asp:Label>
    
        <br />
        <asp:Label ID="Label2" runat="server"></asp:Label>
    </div>
    <p>
        &nbsp;</p>
    </form>
</body>
</html>

here is other part in case you need it

Recommended Answers

Set the PassWordChar property of your textbox to '*'.
Put this in your eventhandler:

// Show the text you typed so far
            MessageBox.Show(textBox1.Text);
Jump to Post

To disable the password character ('*') and display the actual text in the same control:

TxtPassword.UseSystemPasswordChar = false;// or true to turn back on
Jump to Post

If you set TxtPassword.UseSystemPasswordChar = true;
whenever you type something in your textbox it will be replaced by the bullet character.
If you use TxtPassword.PasswordChar = '$' or '*', all typing in the texbox will be replaced by '$' or '*'.
Put MessageBox.Show(TxtPassword.Text); In your void TxtPassword_TextChanged handler.

Jump to Post

All 10 Replies

Set the PassWordChar property of your textbox to '*'.
Put this in your eventhandler:

// Show the text you typed so far
            MessageBox.Show(textBox1.Text);

where do i put it in the code part i am confused?

To disable the password character ('*') and display the actual text in the same control:

TxtPassword.UseSystemPasswordChar = false;// or true to turn back on

If you set TxtPassword.UseSystemPasswordChar = true;
whenever you type something in your textbox it will be replaced by the bullet character.
If you use TxtPassword.PasswordChar = '$' or '*', all typing in the texbox will be replaced by '$' or '*'.
Put MessageBox.Show(TxtPassword.Text); In your void TxtPassword_TextChanged handler.

If you set TxtPassword.UseSystemPasswordChar = true;
whenever you type something in your textbox it will be replaced by the bullet character.
If you use TxtPassword.PasswordChar = '$' or '*', all typing in the texbox will be replaced by '$' or '*'.
Put MessageBox.Show(TxtPassword.Text); In your void TxtPassword_TextChanged handler.

I believe this is correct. So, if I want to achieve the same goal of turning it off in my textbox (show actual text at runtime) when using my own defined PasswordChar, what would be the technique for switching it on and off as you can with the UseSystemPasswordChar property?

@DdoubleD
Just set PasswordChar=''; to get back normal behavior in a textBox.

@Ramy
You are absolutely right, but the line is sometimes thin...

its not working

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

        
       
        protected void TxtPassword_TextChanged1(object sender, EventArgs e)
        {
            Label2.Text = false;  ?????
        }
}

what belongs here to get the password to show up what do i type for event handler i forget this part

The Text property of a Label or a TextBox is of type string, not of type boolean. So assigning false to a Label.Text will not work.
Try this: Label.Text = TxtPassword.Text; and see what happens!
Good luck.

You can also set the password property in your .aspx markup:

<asp:TextBox ID="TextBoxPassword" runat="server" TabIndex="2" Width="200px" CssClass="inputBox" TextMode="Password"></asp:TextBox>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.