Set value of 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" />

I am trying to set its value using C # and ASP.Net before the page loads, but I cannot get it to work.

+3
source share
5 answers

Do not set the input type in your markup, or ASP.NET will clear the input before rendering it. Use the following markup instead:

<input id="tbPassword" name="password" runat="server" />

... and the following code in the code:

tbPassword.Value = "your password";
tbPassword.Attributes["type"] = "password";

However, I highly recommend this approach. First, you should not store passwords in text format. This is a really bad security practice.

, , ? ( ). , .

+9

<asp:TextBox>, TextBox.Attributes.Add value .

:

TextBox1.Attributes.Add("value", "My Sample Password");
+1

. ? ?

0

, , .

User passwords should be stored as a cryptographic hash in your database, which cannot be canceled in the plaintext password, it is checked only for compliance.

If what you want to do is pre-load the user's password in the input field to save him typing, just do not do this, because a custom web browser will probably be better at handling this.

0
source

Have you tried something like this:

void Page_Load(object sender, eventargs e)
{
   password.value= "something";
}
-2
source

All Articles