0

By default, the password fieldbox masked all the text the user typed as **.

I want to be able to display a string on the Password field box.

So it should says "Please enter your Password" initially when the password control is loaded.

Currently aspx showing it as *******

How can i best achieve this?

Cheers

ove
  • 3,092
  • 6
  • 34
  • 51

2 Answers2

1

Use TextMode.

<asp:TextBox ID="Password" runat="server" TextMode="Please enter your Password"  
onclick="this.value=''; this.type='password'; ">Password                                                    
</asp:TextBox>

or

Use placeholder.

For EX:

<input type="password" placeholder="Please enter your Password">
Monie corleone
  • 1,618
  • 1
  • 16
  • 37
  • This is not a password textbox. I want to be able to show the password masked when the user type – ove Mar 21 '13 at 10:09
1

You can achieve it using jquery:

HTML:

<input id="password" value="password" class="password-input" />

JS:

$('.password-input').bind('click', function() {
    if ($(this).val() === "Please enter your Password")
    {
       this.type = "password";
       $(this).val(''); 
    }
});

$('.password-input').bind('blur', function() {
    if ($(this).val() === "")
    {
       this.type = "text";
       $(this).val('Please enter your Password');
    }
});

JSFIDDLE:

http://jsfiddle.net/V2Dh5/3/

You can also see previous SO questions about the same thing:

Set default value of a password input so it can be read

Set Default Value Of A Password Input / A Scenario / Issue in IE 8

default value for asp.net textbox -> TextMode = password

Community
  • 1
  • 1
talha2k
  • 24,937
  • 4
  • 62
  • 81