10

での使い方はありautocomplete="off"ます<asp:Login> </asp:login>か?asp:login をテンプレートに変換し、autocomplete="off" 属性を asp:TextBox 要素に配置しようとしましたが、これによりログイン プロセスの他の部分が壊れます。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");
        }
    } 

そしてここに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>
4

3 に答える 3

3

これを試して:

.aspx

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

コードビハインド

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;
}

これはパスワード フィールドの例です。ユーザー名には、メソッドの 2 番目のパラメーターに「Password」ではなく「UserName」を使用しますFindControlRecursive

于 2013-10-23T10:07:30.510 に答える