使用FireFox在UpdatePanel内的GridView内使用ButtonField触发按钮命令两次

时间:2010-02-06 18:09:11

标签: ajax firefox updatepanel asp.net-3.5

我有一个包含GridView的更新面板,其中有一个ButtonField。每当我按下按钮,我都会看到Firefox做两个POST(通过Firebug)。一个人立即中止,但确实到达了服务器。这会导致我的服务器端代码出现问题,因为命令(副本)会被执行两次。

IE6和IE8不会出现此行为。

任何人都知道造成这种情况的原因或我能做些什么呢?

我已设法在此页面上将问题重现到最低限度:

<form id="form1" runat="server">
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
    <Data>
<bla>
<wibble wobble="1" />
</bla></Data>
</asp:XmlDataSource>
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>

    <asp:Label runat="server" ID="Counter" Text="0"></asp:Label>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="XmlDataSource1" onrowcommand="GridView1_RowCommand">
        <Columns>
            <asp:BoundField DataField="wobble" HeaderText="wobble" 
                SortExpression="wobble" />
            <asp:ButtonField HeaderText="wobble" CommandName="IncrementWobble"
                SortExpression="wobble" ButtonType="Image" ImageUrl="icons/page_copy.png" Text="increment" />
        </Columns>
    </asp:GridView>
 </ContentTemplate>
</asp:UpdatePanel>

</form>

在制作这个小版本时,我注意到问题只发生在ButtonType =“Image”而不是ButtonType =“Button”。

为完整起见,事件处理程序:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "IncrementWobble")
    {
        int count = Int32.Parse(Counter.Text) + 1;
        Counter.Text = count.ToString();
    }
}

1 个答案:

答案 0 :(得分:0)

here,我找到了解决方法:

使用包含ButtonField的{​​{1}}替换TemplateField解决问题。对我来说足够好,但在ASP .NET或FireFox中似乎仍然是一个错误。