zoukankan      html  css  js  c++  java
  • GridView中的ButtonType="Image"会导致回发两次

    /* from: http://www.dotneteer.com/Weblog/post/2006/03/Page-postback-twice-in-ASPNET-20-when-ButtonType-is-set-to-Image-in-GridView.aspx */

    以下为全文引用,我没有验证:

    Page postback twice in ASP.NET 2.0 when ButtonType is set to Image in GridView

    This problem has driven me nuts for several hours before I found an answer.

    I have GridView control that contains two command fields. When I clicked on the button, the page always got posted twice. After more testing, I found that this only occurs when the ButtonType is set to “Image”. The problem does not occur when the ButtonType is “Link” or “Button”.

    On further Google search, I found the following:

    This bug has been forwarded to Microsoft.
    This is the answer from Microsoft Bug adn reported issues:

    Thanks for reporting the issue. This is a known issue and we are
    investigating fixing this in the next service pack. For the time being
    you could use the following work around. One obvious workaround is to
    change the button type to a regular button or a link button. If you need
    an ImageButton, then you can put an ImageButton in a TemplateField. You
    may need to handle the Command event on the ImageButton and call
    DeleteRow, passing the RowIndex as the CommandArgument, like this:

    <asp:GridView ID="GridView1" runat="server">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:ImageButton runat=server id="ImageButton1" CommandName="Delete"
    ImageUrl="..." CommandArgument='<%# DataBinder.Eval(Container,
    "RowIndex") %>' OnCommand="ImageButton1_Command" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    protected void ImageButton1_Command(object sender, CommandEventArgs e) {
    GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString()));

    }

    Thanks,
    The Web Platform and Tools Team

  • 相关阅读:
    ES6 解构
    flutter
    selenium
    selenium
    python
    selenium
    selenium
    selenium
    selenium
    selenium- SMTP发送邮件
  • 原文地址:https://www.cnblogs.com/kofkyo/p/2297292.html
Copyright © 2011-2022 走看看