Hello If you want to validate a textbox where we can only enter numbers.

Fisrt write the javascript function in .aspx file.

eg:

<SCRIPT language=Javascript>
<!–
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;

return true;

}
//–>
</SCRIPT>

In the code behind in page_load event write the code for the text box control.

<!–

TextBox1.Attributes.Add(“Onkeypress”, “return isNumberKey(event)”);

>

Advertisement