密码框不显示任何内容

发布于 2024-10-12 02:53:52 字数 897 浏览 2 评论 0原文

我有一个小型网络解决方案,需要用户输入密码。我有两个输入框

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

如果我将一些字符设置为控件的值属性,如下所示:

m_txtPassword1.Value="someChars";

密码框呈现为空。没有显示项目符号。如果我查看渲染的 html 源,也没有渲染值标签。如果我将类型更改为

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

显示的字符。这是设计使然吗?如何禁用此功能?
请注意,我不想将真实的密码放入值属性中,我只想向用户显示已经设置了密码,而在我看来,在输入控件中使用 8 个项目符号可以最好地做到这一点。但为此,我需要能够设置控件的值属性。

更新

对于所有人,遇到同样的问题:我尝试声明 具有相同的结果。另外 m_txtPassword1.Attributes["value"]="someChars" 也没有帮助。

看来,这确实是不可能的。

作为解决方法,我将密码框声明为纯 html,没有 runat="server",并在标记中设置了值属性(通过代码隐藏中的两个属性)。不太好,但我真的想向用户显示他已经输入了密码。
另一种解决方法是在加载时通​​过 javascript 设置该值。

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 into 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

扎心 2024-10-19 02:53:52

这是默认情况。您无法设置密码。

This is by default. You cannot set a password.

疯了 2024-10-19 02:53:52

我做到了,

<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>

试试这个:
http://jsbin.com/ocexo5

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

尸血腥色 2024-10-19 02:53:52

出于安全原因,这是设计使然 - 因此密码不会出现在
纯文本 HTML。

现在,您可以编写 javascript 来设置文本框的 value 属性
在客户端,当然这仍然意味着您拥有密码
HTML 中的纯文本。

以下是页面示例:

标记:

<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"/>

和隐藏代码:

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); 
        }
    }

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); 
        }
    }
嘿哥们儿 2024-10-19 02:53:52
Textbox11.Attributes.Add("Value",whatever_your_password_is)
Textbox11.Attributes.Add("Value",whatever_your_password_is)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文