My recommendation is to utilize ASP.NET controls such as RangeValidator
or CompareValidator
.
Here is an example for you:
Markup
<head runat="server">
<title></title>
<script type="text/javascript>
function NumericChk(obj, val) {
if (obj.value > val) {
obj.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox>
</form>
</body>
Make sure to add the "onblur" attribute using code-behind.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int value = 10;
string handle=string.Format("return NumericChk(this,{0})",value);
TextBox1.Attributes.Add("onblur", handle);
}
}