Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top