TemplateField 按钮导致 GridView 无效回发 [英] TemplateField button causing GridView Invalid Postback

查看:22
本文介绍了TemplateField 按钮导致 GridView 无效回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我在 gridview 中有一个模板字段,其中只包含一个简单的按钮...

Ok, so I've got a template field in a gridview that contains just a simple button...

<%@ 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>

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

Whenever I click the button I get the error...

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 的文章...

I've found a decent amount of articles referencing this issue, including a couple on SO, for example...

无效的回发或回调参数.使用 ''

还有……

无效的回发或回调参数

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

I might just be misunderstanding, but as far as I can tell they don't really help me. How do I get this to go away without setting enableEventValidation="false"?

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

EDIT Posted all the code for my page.

推荐答案

这个家伙找到了类似问题的解决方案(向下滚动到第 4 条评论),即为 GridView 按钮设置唯一 ID.

This fellow found a solution to a similar problem (scroll down to about the 4th comment), which was to set unique id's for the GridView buttons.

这篇关于TemplateField 按钮导致 GridView 无效回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆