Add another validator to the text box
<asp:CustomValidator runat="server"
ID="CustomValidator"
ControlToValidate="TxtPassword"
ClientValidationFunction="checkforlength"
ValidateEmptyText="true"
Text="Error!">
</asp:CustomValidator>
Also update your javascript function
function checkforlength(sender, args) {
if (args.Value.length > 20) {
alert("password exceeded the range");
return false;
}
else {return true;}
}