Firstly Write Java Script Function in <head tag> in Asp.Net
After That Call Function <OnKeyPress > on TextBox
Ex.
<head>
<script type="text/javascript">
var specialKeys = new Array();
specialKeys.push(8); //Backspace
function IsNumeric(e)
{
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
document.getElementById("error").style.display = ret ? "none" : "inline";
return ret;
}
</script>
</head>
Call On TextBox
ex.
<table>
<tr>
<td> Employee Salary<td>
<td>:</td>
<td>
<asp:TextBox ID="tbnEmpSalary" runat="server" MaxLength="12" onkeypress="return IsNumeric(event)"></asp:TextBox>
<span id="error">* Input digits (0 - 9)</span>
</td>
</tr>
</table>
OutPut