错误:无效的回发或回调参数

我在使用gridview单击按钮时收到以下错误

Server Error in '/' Application. Invalid postback or callback argument. Event validation is enabled using  in configuration or  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  in configuration or  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  in configuration or  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 

当我按下gridview内的按钮时会发生这种情况,奇怪的是我有另一个gridview,也有一个运行不同代码的列中的自定义按钮,但没有错误。 下面是页面和代码隐藏的代码。

 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(); } } } 

和实际页面:

          
<asp:Button ID="NewCustomerDoneButton" runat="server" CommandName="" Text="Done" CommandArgument='' OnClick="NewCustomerDoneButton_Click" CausesValidation="False" /> <asp:SqlDataSource ID="NewCustomers" runat="server" ConnectionString="" 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))">

我现在想知道,这与GridViewAjax Tab Container内的事实有什么关系吗? 因为我的另一张表工作正常不是……

注意:由于字符限制,不得不从页面中删除一些代码

1)GridView中的无效回发或回调参数问题可能是:您正在使用对象数据源或带有函数调用的手动绑定将Page_Load事件中的数据绑定。 这将使您的GridView绑定任何控件的每个事件触发数据。

当您使用OnRowCommand触发任何GridView命令时,在RowCommand触发之前,您的GridView将重新绑定,并且其中的所有控件都将分配给新的id。 因此RowCommand无法获取已触发事件的项目。

GridView中无效回发或回调参数的解决方案:您可以在此if条件下绑定数据

 if (!IsPostBack) { //Your code for Bind data } 

如果这不起作用,这个代码肯定会给你解决方案,然后检查是否有任何其他控件没有给出错误。

你是通过javascript或Ajax更新网格或任何此类控件。

如果是这种情况,那么您可能会面临这种情况。 可能的解决方案是将EnableEventValidation设置为false。

一些事情要尝试

  1. Page Load事件中,添加对!Page.IsPostBack的检查并在那里移动非validation代码块。
  2. 使用LinkButton而不是常规按钮进行实验。

这可能是因为您正在使用的任何第三方控件。

我也有这个错误。 在我的情况下,我在更新面板和内部转发器控件内有一个转发器控件我正在使用telerik datepicker控件。 它在IE中运行良好,但在mozilla和chrome中没有。 我通过从chrome和IE发送请求检查了两种情况下的表单数据,发现触发控制值略有不同。 我使用telerik RadAjaxmanager而不是updatepanel错误消失了。

我测试了上述所有解决方案和其他post,但我的问题没有完成。

在服务器端的网格事件结束时取消事件时,我的问题得以解决。

当我们使用gridview的edit事件时会发生这种类型的问题。 只需添加e.Cancel = true; 在活动结束时。

 protected void grdEducation_RowEditing(object sender, GridViewEditEventArgs e) { // do your processing ... // at end e.Cancel = true; }