【问题标题】:How to avoid having to double click when inside of a UpdatePanel?如何避免在 UpdatePanel 内双击?
【发布时间】:2018-04-27 10:53:26
【问题描述】:

我正在使用 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 的答案。我希望我的按钮不必双击,这样它就不会回发并激活验证器。

【问题讨论】:

标签: c# asp.net ajax


【解决方案1】:

我设法通过使用“嵌套技巧”并将 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>

感谢您的耐心和善意。 :)

【讨论】:

    猜你喜欢
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    • 2015-05-29
    • 2017-11-25
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    相关资源
    最近更新 更多