将选项“显示密码”添加到asp.net登录控件

Mos*_*she 5 .net asp.net authentication login-control visual-studio

我在 ored 中使用了 asp.net 登录控件来登录我的网站,问题是我想添加一个选项来显示密码(而不是星号),但我无法访问密码文本框,因此无法更改其文本模式。

任何的想法?

小智 5

使用复选框显示密码选项

onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'"
Run Code Online (Sandbox Code Playgroud)

甚至我们可以使用复选框的 onclick 事件。参考代码


Muh*_*tar 4

LayoutTemplate在登录控件中可用,您可以完全更改布局以及您想要的任何其他内容。这是为我在一个项目中使用的登录页面设计的完整布局。

 <asp:Login ID="Login1" runat="server">
    <LayoutTemplate>
        <table>
            <tr>
                <td align="right">
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                        ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="Password" runat="server" ></asp:TextBox>
                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td align="right">
                    &nbsp;
                </td>
                <td>
                    <asp:CheckBox ID="RememberMe" runat="server" CssClass="hint hide" Text="Remember me next time." />
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2" style="color: Red;">
                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2">
                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />
                </td>
            </tr>
        </table>
    </LayoutTemplate>
</asp:Login>
Run Code Online (Sandbox Code Playgroud)