. I tried converting asp: t...">

How to disable autocomplete in asp: login control?

Is there a way to use autocomplete="off" in <asp:Login> </asp:login> . I tried converting asp: to enter the template and put the autocomplete = "off" attribute in asp: TextBox, however this breaks another part of the login process. Is there a way to disable autocomplete without using javascript and without converting to a template. if its possible code is delayed. Looking forward to your suggestions. Thanks

Here is the code in 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"); } } 

And here is the aspx page:

 <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> 
+6
source share
2 answers

To disable autocomplete for the entire form, all you have to do is add an attribute to your form tag, for example:

 <form id="Form1" method="post" runat="server" autocomplete="off"> 

Simple enough. Now you will not get auto-completion on any of the form controls, it works for any browser that supports auto-completion. HTML INPUT tags also support the use of autocomplete = off, and since the control appears as INPUT tags, you can use it to set it to the control based on the control principle. Just add it to the TextBox at design time (but note that VS.NET will underline it with a wriggling expression that the text field does not have an attribute for autocomplete, but it will work anyway):

 <asp:TextBox Runat="server" ID="Textbox1" autocomplete="off"></asp:TextBox> 

or at runtime:

 Textbox1.Attributes.Add("autocomplete", "off"); 
+8
source

Try the following:

.aspx

 <asp:Login runat="server" ID="login"></asp:Login> 

Code for

 protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { var control = FindControlRecursive(login, "Password") as TextBox; control.Attributes.Add("autocomplete", "off"); } } 
 public Control FindControlRecursive(Control root, string id) { Control first = null; foreach (Control c in root.Controls) { Control t = FindControlRecursive(c, id); if (t != null) { first = t; break; } } return root.ID == id ? root : first; } 

This is an example of the Password field. For the username, use "UserName" instead of "Password" for the second parameter of the FindControlRecursive method.

+2
source

Source: https://habr.com/ru/post/956545/