我正在使用GridView制作CRUD,但是当我在使用UpdatePanel时尝试编辑一行时,我必须双击它以使其工作而不是仅单击一次,而且当我双击它时它导致我的验证器显示和回发(我不想要)。像这样:
这是按钮的设计代码:
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ImageButton ID="btnEdit" CausesValidation="false" CssClass="btnOPTIONS" runat="server" ImageUrl="~/imgBTN/edit.png" Width="30px" Height="30px" ToolTip="Edit" CommandName="Edit" />
<asp:ImageButton ID="btnDelete" CausesValidation="false" runat="server" ImageUrl="~/imgBTN/delete.png" Width="30px" Height="30px" ToolTip="Delete" CommandName="Delete" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnDelete" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="btnUpdate" CausesValidation="false" CssClass="btnOPTIONS" runat="server" ImageUrl="~/imgBTN/save.png" Width="30px" Height="30px" ToolTip="Update" CommandName="Update" />
<asp:ImageButton ID="btnCancel" CausesValidation="false" runat="server" ImageUrl="~/imgBTN/cancel.png" Width="30px" Height="30px" ToolTip="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
编辑:我的问题是寻找一个轻松的不同答案,因为我已经尝试过How to use update panel on button click asp的答案。我希望我的按钮不必双击,所以它不会做回发和激活验证器。
答案 0 :(得分:0)
我设法通过使用“嵌套技巧”并将UpdatePanel移动到EditItemTemplate来修复此问题,现在它看起来像这样并且工作正常:
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView EmptyDataText="No hay registros en la base de datos!" ID="gvImages" runat="server" DataKeyNames="idcountry" AutoGenerateColumns="false" Height="300px" OnRowEditing="gvImages_RowEditing"
OnRowCancelingEdit="gvImages_RowCancelingEdit" OnRowUpdating="gvImages_RowUpdating" OnRowDeleting="gvImages_RowDeleting" AllowPaging="true" OnPreRender="gvImages_PreRender" PageSize="6"
OnPageIndexChanging="gvImages_PageIndexChanging">
<Columns>
<asp:BoundField DataField="idcountry" HeaderText="ID" ReadOnly="true" />
<asp:TemplateField HeaderText="Relacion">...</asp:TemplateField>
<asp:TemplateField HeaderText="Nombre">...</asp:TemplateField>
<asp:TemplateField>...</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>2ImageButtons...blah,blah</ItemTemplate>
<EditItemTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:ImageButton ID="btnUpdate" CausesValidation="false" CssClass="btnOPTIONS" runat="server" ImageUrl="~/imgBTN/save.png" Width="30px" Height="30px" ToolTip="Update" CommandName="Update" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpdate" />
</Triggers>
</asp:UpdatePanel>
<asp:ImageButton ID="btnCancel" CausesValidation="false" runat="server" ImageUrl="~/imgBTN/cancel.png" Width="30px" Height="30px" ToolTip="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
感谢您的耐心和善意。的:)强>