0

我在下面textbox有.itemtemplate of gridview.问题是当我点击时edit button of gridview,如果我textbox根据验证逻辑输入无效值,focus of textbox is lost当我点击update button..如果我在第 30 行焦点转到最上面的行..如何防止焦点..

<asp:TextBox ID="tbattendence"  Width="40px" runat="Server" Text='<%# Eval("attendence") %>' onkeydown = "return (event.keyCode!=13);">
                            </asp:TextBox>
                        </td>
                        <td>
                              <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbattendence"
                ErrorMessage="Attended Attendence is required!"  Display="Dynamic"  ValidationGroup="bottom" 
               ForeColor="#6600FF">*</asp:RequiredFieldValidator>

              <asp:CompareValidator ID="CompareValidator" runat="server"  ErrorMessage="Attended Attendence must be Lesser!"
                                ControlToValidate="tbattendence" ControlToCompare="tbcutoff"  
                                Display="Dynamic" Operator="LessThanEqual" Type="Integer" ValidationGroup="bottom">*</asp:CompareValidator>  
4

1 回答 1

1

添加

SetFocusOnError="true"

像这样的验证控件

 <asp:RequiredFieldValidator ID="RequiredFieldValidator2" SetFocusOnError="true" ...
于 2013-03-16T06:49:39.847 回答