C# password TextBox in a ASP.net website

2019-02-02 20:37发布

问题:

I'm trying to create a ASP .NET website that masks the password in a registration page as the user types. I found sites that use windows form but it doesn't work for a ASP .NET website.

So if the user types in a password its masked like this

 *******

Any website or suggestion on how I can get it to work would be great.

回答1:

To do it the ASP.NET way:

<asp:TextBox ID="txtBox1" TextMode="Password" runat="server" />


回答2:

//in aspx page

<asp:TextBox ID="password" runat="server" TextMode="Password" />

//in MVC cshtml

@Html.Password("password", "", new { id = "password", Textmode = "Password" })


回答3:

Use the password input type.

<input type="password" name="password" />

Here is a simple demo http://jsfiddle.net/cPaEN/



回答4:

I think this is what you are looking for

 <asp:TextBox ID="txbPass" runat="server" TextMode="Password"></asp:TextBox>


回答5:

@JohnHartsock: You can also write type="password". It's acceptable in aspx.

<asp:TextBox ID="txtBox" type="password" runat="server"/>


回答6:

Simply select texbox property 'TextMode' and select password...

<asp:TextBox ID="TextBox1" TextMode="Password" runat="server" />