添加选项";“显示密码”;到asp.net登录控件
我在Order中使用asp.net登录控件来登录我的站点。问题是我想添加一个选项来显示密码(而不是星号),但我无法访问密码文本框,因此无法更改其文本模式添加选项";“显示密码”;到asp.net登录控件,.net,asp.net,visual-studio,authentication,login-control,.net,Asp.net,Visual Studio,Authentication,Login Control,我在Order中使用asp.net登录控件来登录我的站点。问题是我想添加一个选项来显示密码(而不是星号),但我无法访问密码文本框,因此无法更改其文本模式 有什么想法吗?LayoutTemplate在登录控件中可用,您可以完全更改布局和其他任何您想要的内容。这里是一个为我在一个项目中使用的登录页面设计的完整布局 <asp:Login ID="Login1" runat="server"> <LayoutTemplate> <table>
有什么想法吗?
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">
</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>
用户名:
*
密码:
*
甚至我们也可以使用复选框的onclick事件 我的显示/隐藏密码控制方式包含了穆罕默德·阿赫塔和凯萨瓦拉普·文卡特什的答案。我使用了类似于Muhammad的ASP.NET登录控件,但也使用了类似于Kesavarapu代码的复选框。我的复选框和他的复选框之间的区别是JavaScript获得的ID,它是“”而不是“密码”,因为我们访问的是ASP.NET登录控件而不是常规文本框
<asp:Login ID="logUsers" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" FailureText="" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="logUsers_Authenticate" UserNameRequiredErrorMessage="Username is required.">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
</asp:Login>
<input type="checkbox" onchange="document.getElementById('<%=((TextBox)logUsers.FindControl("Password")).ClientID %>').type = this.checked ? 'text' : 'password'" /> Show password
显示密码
您能告诉我们为什么要更改默认行为吗?@Muhammad Akhtar:可能是因为星号是长密码的次要PITA,对于web应用程序和皇家PITA来说,通常是完全不需要的,因为在使用手机设备键入时,手机设备通常不会选择您认为正在键入的同一个字母。
<asp:Login ID="logUsers" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" FailureText="" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="logUsers_Authenticate" UserNameRequiredErrorMessage="Username is required.">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
</asp:Login>
<input type="checkbox" onchange="document.getElementById('<%=((TextBox)logUsers.FindControl("Password")).ClientID %>').type = this.checked ? 'text' : 'password'" /> Show password