asp.net onkeyup event for textbox

前端 未结 1 1881
遥遥无期
遥遥无期 2020-12-22 08:36

I have an issue with onkeyup event with textbox. my function is to check password strength of the password textbox. so when a users enter his password, it will call the func

相关标签:
1条回答
  • 2020-12-22 08:55

    Every control that is included in an ASP.NET Web page must contain a unique identifier (ID). To maintain this uniqueness ASP.Net change the ID of control when the page gets rendered into HTML.

    Here, if below control is inside <asp:ContentPlaceHolder> then the ID is likely to gets changed into ctl00$ctl00$ContentPlaceHolder$tb_password for example.

    <asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()"></asp:TextBox>
    

    To overcome this what you can do it either use Client Mode in mark-up or use ClientID in javascript.

    Method 1:

    <asp:TextBox ID="tb_password" runat="server" TextMode="Password" onKeyUp="checkPasswordStrength()" ClientMode="Static"></asp:TextBox>
    

    Method 2:

    var passwordTextbox = document.getElementById("<%=tb_password.ClientID%>");
    .
    .
    .
    .
    document.getElementById("<%=lbl_passwordStrength.ClientID%>").innerHTML = strength;
    passwordTextbox.style.color = "white";
    passwordTextbox.style.backgroundColor = backgroundColor;
    
    0 讨论(0)
提交回复
热议问题