title: Error: Invalid postback or callback argument
body: <p>I am getting the following error on a button click with gridview</p>
  
  <pre><code> Server Error in '/' Application.
  Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; 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.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
  Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; 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.
  
  Source Error:
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace:
  
  
  [ArgumentException: Invalid postback or callback argument.  Event validation is enabled using &lt;pages enableEventValidation="true"/&gt; in configuration or &lt;%@ Page EnableEventValidation="true" %&gt; 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.]
     System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +144
     System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +111
     System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +29
     System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
  
  
  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
  </code></pre>
  
  <p>It occurs when I press a button inside the gridview, and the odd thing is that I have another gridview, also with custom button in a column that runs different code, but gives no errors. Below is the code for the page and the codebehind.</p>
  
  <pre><code>namespace CCCC
  {
      public partial class drivermangement : System.Web.UI.MasterPage
      {
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
              {
                  if (Roles.IsUserInRole("Administrator"))
                  {
                      LoggedInUser.Value = Convert.ToString(Request.QueryString["driver"]);
                  }
                  else
                  {
                      LoggedInUser.Value = Membership.GetUser().UserName.ToString();
                  }
                  DayOfTheWeekHiddenField.Value = Convert.ToString(Request.QueryString["dow"]);
              }
              else
              {
                  Response.Redirect("default.aspx");
              }
              if (NewCustomersGrid.Rows.Count == 0)
              {
                  NewCustomersLabel.Visible = false;
              }
              else
              {
                  NewCustomersLabel.Visible = true;
              }
              if (NeedCompostGrid.Rows.Count == 0)
              {
                  NeedCompostLabel.Visible = false;
              }
              else
              {
                  NeedCompostLabel.Visible = true;
              }
              if (CanceledGrid.Rows.Count == 0)
              {
                  CanceledLabel.Visible = false;
              }
              else
              {
                  CanceledLabel.Visible = true;
              }
              if (VacationGrid.Rows.Count == 0)
              {
                  VacationLabel.Visible = false;
              }
              else
              {
                  VacationLabel.Visible = true;
              }
              if (NewCustomersGrid0.Rows.Count == 0)
              {
                  NewCustomersLabel0.Visible = false;
              }
              else
              {
                  NewCustomersLabel0.Visible = true;
              }
              if (NeedCompostGrid0.Rows.Count == 0)
              {
                  NeedCompostLabel0.Visible = false;
              }
              else
              {
                  NeedCompostLabel0.Visible = true;
              }
              if (CanceledGrid0.Rows.Count == 0)
              {
                  CanceledLabel0.Visible = false;
              }
              else
              {
                  CanceledLabel0.Visible = true;
              }
          }
  
          protected void NewCustomerDoneButton_Click(object sender, EventArgs e)
          {
              int CustomerID = Convert.ToInt32(((Button)sender).CommandArgument);
              string CustomerBinNeedAcknowledged = "Yes";
              string strConnString = "Data Source";
              using (SqlConnection con = new SqlConnection(strConnString))
              {
                  using (SqlCommand cmd = new SqlCommand())
                  {
                      cmd.Connection = con;
                      cmd.CommandType = CommandType.Text;
                      cmd.CommandText = "UPDATE Customers SET CustomerBinNeedAcknowledged=@CustomerBinNeedAcknowledged WHERE CustomerID=@CustomerID";
                      cmd.Parameters.AddWithValue("@CustomerBinNeedAcknowledged", CustomerBinNeedAcknowledged);
                      cmd.Parameters.AddWithValue("@CustomerId", CustomerID);
                      con.Open();
                      cmd.ExecuteNonQuery();
                      con.Close();
                  }
              } 
         }
  </code></pre>
  
  <p>and the actual page:</p>
  
  <pre><code>&lt;%@ Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="CCCCCC.drivermangement" CodeBehind="drivermangement.master.cs" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;asp:HiddenField ID="LoggedInUser" runat="server" /&gt;
      &lt;asp:HiddenField ID="DayOfTheWeekHiddenField" runat="server" /&gt;
      &lt;ajaxToolkit:TabContainer ID="RoutingTabs" runat="server" ActiveTabIndex="0" 
          Width="900px"&gt;
          &lt;ajaxToolkit:TabPanel runat="server" HeaderText="Pre-Route" ID="PreRouteTab"&gt;
          &lt;ContentTemplate&gt;
  &lt;br /&gt;
  &lt;asp:Label ID="NewCustomersLabel" runat="server" 
          style="font-weight: 700; font-size: large; color: #009933" Text="New Customers"&gt;&lt;/asp:Label&gt;
  
  &lt;asp:GridView ID="NewCustomersGrid" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" 
          BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
          DataKeyNames="CustomerId" DataSourceID="NewCustomers" ForeColor="Black" 
          GridLines="Vertical"&gt;
  &lt;AlternatingRowStyle BackColor="#99FF99" &gt;&lt;/AlternatingRowStyle&gt;
  &lt;Columns&gt;
  &lt;asp:BoundField DataField="CustomerFullName" HeaderText="Name" 
                  SortExpression="CustomerFullName" /&gt;
  &lt;asp:BoundField DataField="CustomerFullAddress" HeaderText="Address" 
                  SortExpression="CustomerFullAddress" /&gt;
  &lt;asp:BoundField DataField="CustomerNeedsBin" HeaderText="Needs Bin?" 
          SortExpression="CustomerNeedsBin" /&gt;
  &lt;asp:TemplateField ShowHeader="False"&gt;&lt;ItemTemplate&gt;
                  &lt;asp:Button ID="NewCustomerDoneButton" runat="server" CommandName="" 
                  Text="Done" CommandArgument='&lt;%# Eval("CustomerID") %&gt;' OnClick="NewCustomerDoneButton_Click" CausesValidation="False" /&gt;
  
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  &lt;asp:SqlDataSource ID="NewCustomers" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:tcc_customersConnectionString %&gt;" 
  
                  SelectCommand="SELECT [CustomerId], [CustomerStatus], [CustomerFullName], [CompanyName], [CustomerFullAddress], [CustomerPickUpDay], [CustomerPickUpDay2], [CustomerDriver], [CustomerNeedsBin], [CustomerBinNeedAcknowledged] FROM [Customers] WHERE (([CustomerBinNeedAcknowledged] = @CustomerBinNeedAcknowledged) AND ([CustomerNeedsBin] = @CustomerNeedsBin) AND ([CustomerDriver] = @CustomerDriver) AND ([CustomerStatus] = @CustomerStatus) AND ([CustomerPickUpDay] = @CustomerPickUpDay OR [CustomerPickUpDay2] = @CustomerPickUpDay2))"&gt;&lt;SelectParameters&gt;
  &lt;asp:Parameter DefaultValue="No" Name="CustomerBinNeedAcknowledged" Type="String" /&gt;
  &lt;asp:Parameter DefaultValue="Yes" Name="CustomerNeedsBin" Type="String" /&gt;
  &lt;asp:ControlParameter ControlID="LoggedInUser" Name="CustomerDriver" 
              PropertyName="Value" Type="String"&gt;&lt;/asp:ControlParameter&gt;
  &lt;asp:Parameter DefaultValue="New" Name="CustomerStatus" Type="String" /&gt;
  &lt;asp:ControlParameter ControlID="DayOfTheWeekHiddenField" Name="CustomerPickUpDay" 
                  PropertyName="Value" Type="String" &gt;&lt;/asp:ControlParameter&gt;
  &lt;asp:ControlParameter ControlID="DayOfTheWeekHiddenField" 
              Name="CustomerPickUpDay2" PropertyName="Value" Type="String" /&gt;
  &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  
  &lt;/ContentTemplate&gt;
  
  &lt;/ajaxToolkit:TabPanel&gt;
          &lt;ajaxToolkit:TabPanel runat="server" HeaderText="Post-Route" ID="PostRouteTab"&gt;&lt;ContentTemplate&gt;
  </code></pre>
  
  <p>I'm now wondering, does this have anything to do with the fact that the <code>GridView</code> is inside an <code>Ajax Tab Container</code>? Cause my other table that works fine is not...</p>
  
  <p>Note: had to cut some code from page due to character limits</p>