设置类型的输入变量的值="密码"使用C#和ASP.Net [英] Set the value of an input tag with type="password" using C# and ASP.Net
问题描述
所以我有这个输入标签:
So I have this input tag:
<input type="password" id="password" name="password" runat="server" />
我想使用C#和ASP.Net页面加载之前设置的值,但我不能得到它的工作。
I'm trying to set its value using C# and ASP.Net before the page loads, but I can't get it to work.
推荐答案
不要设置输入类型在您的标记或呈现前ASP.NET将清除输入。相反,使用以下标记:
Don't set the input type in your markup or ASP.NET will clear the input before it is rendered. Instead, use the following markup:
<input id="tbPassword" name="password" runat="server" />
...及以下code在code-背后:
...and the following code in your code-behind:
tbPassword.Value = "your password";
tbPassword.Attributes["type"] = "password";
不过,我强烈反对这种做法。其一,你不应该采用明文存储密码。这是一个非常糟糕的安全做法。
However, I strongly advise against this approach. For one, you shouldn't be storing passwords in plain text. It's a really bad security practice.
二,如果你只是要设置code中的密码,为什么需要它呢?一个密码输入的点是为用户交互(输入密码)。如果你这样做对他们来说,然后有在页面上是没有意义的。
Two, if you're just going to set the password in code, why require it at all? The point of a password input is for user interaction (entering a password). If you do that for them, then having it on the page is pointless.
这篇关于设置类型的输入变量的值=&QUOT;密码&QUOT;使用C#和ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!