akd*_*akd 9 c# asp.net autocomplete
是否有使用的方式autocomplete="off"在<asp:Login> </asp:login>.我试图将asp:login转换为模板,并在asp:TextBox元素中放置autocomplete ="off"属性,但这会破坏登录过程的其他部分.有没有一种方法可以在不使用javascript和不转换为模板的情况下禁用自动完成功能.如果它可能背后的代码是好的.期待您的建议.谢谢
这是Page_Load中的代码
if (!Page.IsPostBack)
{
var control = this.FindControlRecursive(LoginArea, "UserName") as TextBox;
if (control != null)
{
control.Attributes.Add("autocomplete", "off");
}
var control2 = this.FindControlRecursive(LoginArea, "Password") as TextBox;
if (control2 != null)
{
control2.Attributes.Add("autocomplete", "off");
}
}
Run Code Online (Sandbox Code Playgroud)
在这里aspx页面:
<asp:Login ID="LoginArea" runat="server" SkinID="Login" CssSelectorClass="PrettyLogin"
DestinationPageUrl="Home.aspx" LoginButtonImageUrl=""
LoginButtonText="login button"
LoginButtonType="Button"
UserNameLabelText="username>"
PasswordLabelText="password"
TitleText="title"
RememberMeSet="false" DisplayRememberMe="false"
FailureText="failed"
ToolTip="tool tip"
PasswordRecoveryText=""
PasswordRecoveryUrl="urlforpasswordrecovery"
CreateUserText=""
CreateUserUrl="" OnLoggedIn="LogOn_LoggedIn"
OnLoggingIn="LogOn_LoggingIn" OnLoginError="LogOn_Error" >
</asp:Login>
Run Code Online (Sandbox Code Playgroud)
Mon*_*ika 11
要关闭整个表单的自动完成功能,您只需在表单标记中添加一个属性,如下所示:
<form id="Form1" method="post" runat="server" autocomplete="off">
Run Code Online (Sandbox Code Playgroud)
很容易.现在,您不会在表单上的任何控件上获得自动完成功能,适用于任何支持自动完成的浏览器.HTML INPUT标记还支持使用autocomplete = off,并且由于控件呈现为INPUT标记,因此您可以使用它来逐个控件地设置它.只需在设计时将它添加到TextBox(但请注意,VS.NET会用一个波浪形的下划线表示文本框没有自动完成的属性 - 但它仍然可以工作):
<asp:TextBox Runat="server" ID="Textbox1" autocomplete="off"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)
或在运行时:
Textbox1.Attributes.Add("autocomplete", "off");
Run Code Online (Sandbox Code Playgroud)