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