So I have this input tag:
<input type="password" id="password" name="password" runat="server" />
I'm trying to set its value using C# and ASP.Net before the page loads, but I can't get it to work.
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" />
...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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With