且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将验证器放置到数据网格中的文本框

更新时间:2023-02-20 15:47:00

选项1:
在Grid内这样的事情怎么样:
OPTION 1:
How about something like this inside the Grid:
<EditItemTemplate>
   <asp:TextBox id="txtReceived"></asp:TextBox>
   <asp:customvalidator id="cvalReceived" runat="server" ClientValidationFunction="ValidateReceivedAmounts" ControlToValidate="txtReceived">
   </asp:customvalidator>
</EditItemTemplate>



选项2:
使用Javascript验证.使用属性将Javascript方法添加到客户端onKeyDown.现在,在JavaScript中,检查输入的值,如果不是整数则显示错误,或者只是取消按下的键.



OPTION 2:
Use Javascript validation. Add a Javascript method to the client side onKeyDown using attributes. Now, in JavaScript, check the value entered and show error if not integer or just cancel out the key pressed.