GridView的RowCommand事件在UpdatePanel的两次射击 [英] GridView RowCommand Event is firing twice in UpdatePanel

查看:255
本文介绍了GridView的RowCommand事件在UpdatePanel的两次射击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临一个奇怪的问题,去年2天。在UpdatePanel内使用时我的GridView的rowcommand事件被触发两次。如果我用它的更新面板之外。它按预期工作。任何人都可以指导我如何解决这个问题。

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.

我的示例code是如下:
ASPX

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

推荐答案

我已经解决了这个问题。而不是使用RowCommand事件,我现在使用的ImageButton的Click事件。它的发射只有一次。

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.

这篇关于GridView的RowCommand事件在UpdatePanel的两次射击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆