Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable autocomplete in asp:login control?

Is there a way of using autocomplete="off" in <asp:Login> </asp:login>. I tried to convert asp:login to template and put the autocomplete="off" attribute in asp:TextBox element however this breaks other part of login process. Is there a way of disabling autocomplete without using javascript and without converting to template. if its possible behind code is fine. Look 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 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>
like image 474
akd Avatar asked Oct 23 '13 09:10

akd


People also ask

How do I turn off auto suggestions on input box?

Use the <input> tag with autocomplete attribute. Set the autocomplete attribute to value “off”.


3 Answers

Follow the following steps

  1. Open Login Web Page in design mode
  2. Select Login Control and click on > and select Convert to Template (if username and password textbox is not visible).
  3. Select Login Textbox an Press F4 to show property window and set AutoCompleteType="Disabled" Similarly for Password. See the attached image.enter image description here
like image 82
Alok Kumar Avatar answered Nov 13 '22 09:11

Alok Kumar


Try this:

.aspx

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

Code behind

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 example for Password field. For user name use "UserName" instead of "Password" for the second parameter of FindControlRecursive method.

like image 36
Uroš Goljat Avatar answered Nov 13 '22 08:11

Uroš Goljat


To turn off auto-complete for your entire form, all you need to do is add an attribute to your form tag, like this:

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

Easy enough. Now you won't get the auto complete on any of the controls on the form, works for any browser that supports auto-complete. The HTML INPUT tags also support the use of autocomplete=off and since the control renders as INPUT tags then you can use it to set it on a control by control basis. Just add it to the TextBox at design-time (but note that VS.NET will underline it with a squiggly saying that textbox does not have an attribute for autocomplete - but it will still work):

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

or at runtime:

Textbox1.Attributes.Add("autocomplete", "off");
like image 29
Monika Avatar answered Nov 13 '22 09:11

Monika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!