views:

183

answers:

2

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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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. 

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

http://stackoverflow.com/questions/228969/asp-net-invalid-postback-or-callback-argument-event-validation-is-enabled-usi

and...

http://stackoverflow.com/questions/103560/invalid-postback-or-callback-argument

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 Posted all the code for my page.

+2  A: 

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.

DOK
I tried something similar earlier, but no luck.
Carter
Ah ha! This was it. I did something stupid and the code setting the IDs wasn't always being run. Thank ya sir!
Carter
A: 

You need to give your button an ID. Just a runat="server" does not meet the minimum information that needs to be provided for a server control to be created.

TheGeekYouNeed
I had a button ID at one point. However, it doesn't matter if it's their or not. The reason my button is so sparse is because I was trying to simplify the problem as much as possible.
Carter
can you post your code for the whole page and for the master page if you're using one?
TheGeekYouNeed
The deed is done. No master page to post.
Carter
thanks for posting the code.
TheGeekYouNeed