asp.net – 导致GridView无效回发的TemplateField按钮

前端之家收集整理的这篇文章主要介绍了asp.net – 导致GridView无效回发的TemplateField按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
好的,所以我在gridview中有一个只包含一个简单按钮的模板字段……
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Administration.aspx.cs"     
Inherits="Administration" %>
<%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">    
    <title>Keywords Administration</title>
</head>
<body class="popupbody">
<form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" CombineScripts="false"></ajaxToolkit:ToolkitScriptManager>

    <asp:Label ID="AddLabel" runat="server">Add a Keyword</asp:Label>
    <br />
    <asp:TextBox ID="AddTextBox" runat="server" />
    <asp:Button ID="AddButton" Text="Add" runat="server" OnClick="AddKeyword_Click" />

    <asp:GridView ID="KeywordsGridView" AllowPaging="false" AutoGenerateColumns="false" BackColor="white"
        GridLines="None" HeaderStyle-CssClass="Table_Header" RowStyle-CssClass="Table_Style" 
        OnRowDataBound="RowBound" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="References" SortExpression="References" HeaderText="Total References" />
            <asp:BoundField DataField="Keyword" SortExpression="Keyword" HeaderText="Keyword" />
        </Columns>
    </asp:GridView>
</form>
</body>
</html>

每当我点击按钮,我都会收到错误

Invalid postback or callback argument.  Event validation is enabled using 
<pages enableEventValidation="true"/> in configuration or <%@ Page 
EnableEventValidation="true" %> in a page.  For security purposes,this feature 
verifies that arguments to postback or callback events originate from the server 
control that originally rendered them.  If the data is valid and expected,use the 
ClientScriptManager.RegisterForEventValidation method in order to register the 
postback or callback data for validation.

我找到了大量引用这个问题的文章,包括一些关于SO的文章,例如……

Invalid postback or callback argument. Event validation is enabled using ‘<pages enableEventValidation=”true”/>’

和…

Invalid postback or callback argument

我可能只是误会,但据我所知,他们并没有真正帮助我.如何在不设置enableEventValidation =“false”的情况下让它消失?

编辑发布了我的页面的所有代码.

解决方法

This fellow找到了类似问题的解决方案(向下滚动到第4条评论),这是为GridView按钮设置唯一ID.
原文链接:/aspnet/247722.html

猜你在找的asp.Net相关文章