I'm using asp.net. I have a login form. I have written Javascript validation function for this in Page.
<table>
<tr>
<td>Username:></td>
<td><asp:TextBox runat="server" id="txtUsername"/></td>
<td>Password:></td>
<td><asp:TextBox runat="server" id="txtPassword"/></td>
<td>Username:></td>
<td><asp:Button runat="server" id="btnLogin" Text="Login" onclientclick="return Validatecp()"/></td>
</tr>
</table>
When I focus on textbox and press enter, the entire page is reloading. I want to show the Validation on enter button press. Is that possible?
Edit:
Validation Function:
function Validatecp() {
var name = document.getElementById('<%=txtName.ClientID %>').value;
var password= document.getElementById('<%=txtTo.ClientID %>').value;
if (name == "") {
document.getElementById("td1").innerHTML = "Name Required.";
return false;
}
else {
document.getElementById("td1").innerHTML = "";
}
if (password== "") {
document.getElementById("td2").innerHTML = "password Required.";
return false;
}
else {
document.getElementById("td2").innerHTML = "";
}
return true;
}