2011-09-05 48 views

回答

0

我建议你使用ASP.NET RangeValidatorCompareValidator控制。

试试这个,

标记

<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> 

通过代码后添加 “的onblur” 属性。

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); 
     } 
    } 
+0

但是在页面加载时,数据库动态地来自数据库。 –