我有一个更新面板,它包含一个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();
}
}