当EnableEventValidation = false时,不会触发Gridview OnRowDeleting事件

时间:2014-06-25 13:57:35

标签: c# asp.net gridview

我正在使用gridview,没有问题绑定它并用代码隐藏的数据填充它。但现在我想使用OnRowDeleting事件,以便我能够从gridview中删除一行。

当我按下删除按钮时出现此错误:

  

0x800a139e - JavaScript运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:无效的回发或回调参数。使用配置或<%@ Page EnableEventValidation =“true”%>启用事件验证在一个页面中。出于安全考虑,此功能可验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。

所以我添加了EnableEventValidation = false,然后当我按下删除按钮时根本没有发生任何事情。事件未被触发(在GridView1_RowDeleting处使用断点进行检查)。

如何在没有任何问题的情况下触发事件?

我的网格视图:

<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing"
    AllowSorting="True" AutoGenerateColumns="False" SkinID="gridviewGridlinesSkin"
    OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" 
    OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"
    EmptyDataText="No positions found" OnRowDataBound="GridView1_RowDatabound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="ibEdit" runat="server" AlternateText="Edit" 
                    CommandName="Edit" ImageUrl="~/Images/icon_edit.gif" />
                <asp:ImageButton ID="ibDelete" runat="server" AlternateText="Delete" 
                    CommandName="Delete" ImageUrl="~/Images/icon_delete.gif" 
                    OnClientClick='<%# Eval("strPositionName", "return confirm(\"Are you sure you want to delete this entry {0}?\");") %>' />
            </ItemTemplate>
            <ItemStyle Wrap="False" />
        </asp:TemplateField>
    //Some controls here
    </Columns>
</asp:GridView>

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    //Make delete with the values from the row but event won't fire
}

0 个答案:

没有答案
相关问题