开发者

Password-Box not showing any content

I have a small websolution that needs the user to input a password. I have two input boxes

<input type="password" runat="server" id="m_txtPassword1"/>

If I set some chars to the Value-property of the control like this:

m_txtPassword1.Value="someChars";

The password box is rendered empty. No bullets are shown. If I look i开发者_如何学编程nto the rendered html-source, also no value-tag has been rendered. If I change the type to

<input type="text" runat="server" id="m_txtPassword1"/>

the chars are shown. Is this by design? How can I disable this feature?

Please note, I don't want to put a real password into the value-property, I only want to show the user that there is already a password set, and this is IMO done best with some 8 bullets in the input-control. But for this, I need the possibility to set the value-property of the control.

Update

For all, having the same problem: I have tried to declare <asp:textbox id="m_txtPassword1" runat="server" TextMode="Password" /> with the same result. Also m_txtPassword1.Attributes["value"]="someChars" has not helped.

It seems that this is realy not possible.

As a workaround, I declared the password-boxes as plain html without the runat="server" and have set the value-property in markup (via two properties from the code-behind). Not nice but I really want to show the user that he has already entered a password.

Another workaround would be to set the value through javascript on load.


This is by default. You cannot set a password.


I make this works,

<html>
<head>
<script type="text/javascript">
function alertValue()
{
alert(document.getElementById("password1").value);
}
function setpassword()
{
   password1.value="someChars";
}
</script>
</head>
<body>

<form>
<input type="password" id="password1" value="" />
<input type="button" id="button1" onclick="alertValue()" value="Show default value" />
<input type="button" id="button2" onclick="setpassword()" value="Set value" />

</form>

</body>
</html>

Try this: http://jsbin.com/ocexo5


It is by design, for security reasons - so that the password is not in the HTML in plain text.

Now, you could write out javascript to set the value property of the textbox on the client, of course this would still mean that you have the password in plain text in the HTML.

Here is example of the page:

Markup:

<script type="text/javascript">
function setPwd()
{
    var Pwd = "<%=Pwd %>";
    var txtText = document.getElementById("MainContent_txtText");
    txtText.value = Pwd;
 }
</script>
<input type="password" id="txtText" runat="server"/>

And code-behind:

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

            Pwd = "password";
            ClientScript.RegisterStartupScript( this.GetType(),"somescript","setPwd();",true); 
        }
    }


Textbox11.Attributes.Add("Value",whatever_your_password_is)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜