GridView RowCommand Event is firing twice in UpdatePanel

只谈情不闲聊 提交于 2020-01-06 15:40:24

问题


I am facing a strange problem for last 2 days. My gridview's rowcommand event is firing twice when used inside the UpdatePanel. If I use it outside the update panel. It works as expected. Can anyone guide me how to solve this problem.

My sample code is below : ASPX

<asp:UpdatePanel ID="upDescription2" runat="server" UpdateMode="Conditional">
    <Triggers>
         <asp:AsyncPostBackTrigge`enter code here`r ControlID="ddlDescription1"    EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
         <asp:DropDownList ID="ddlDescription2" runat="server" Width="70%" AutoPostBack="True"                                                                OnSelectedIndexChanged="ddlDescription2_SelectedIndexChanged">
    </asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>


<asp:UpdatePanel ID="upGrdView" runat="server" UpdateMode="Conditional">
       <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlDescription2" EventName="SelectedIndexChanged" />
       </Triggers>
             <ContentTemplate>
                   <asp:GridView ID="grdView" runat="server" CssClass="grd" AutoGenerateColumns="False"
                        OnRowCommand="grdView_RowCommand" OnRowDataBound="grdView_RowDataBound">
                        <Columns>
                        <asp:ImageButton ID="btnRemove" runat="server" CommandName="remove"/>
                       Blah Column
                       Blah Column
                       Blah Column
                       Blah Column
                      </Columns>
                   </asp:GridView>
     </ContentTemplate>
</asp:UpdatePanel>

C#:

protected void ddlDescription2_SelectedIndexChanged(object sender, EventArgs e)
{
     BindGrid();
}

protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Remove"))
    {
        RemoveRow(e.CommandArgument);  
    }
}

Regards Usman Khalid


回答1:


I have solved the problem. Instead of using RowCommand event, now I am using the Click event of the ImageButton. It's firing only once.



来源:https://stackoverflow.com/questions/12364671/gridview-rowcommand-event-is-firing-twice-in-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!