无效的回发或回调参数 - Telerik网格中的按钮

3
非常出名的错误信息(见下文),根据谷歌搜索结果的数量来判断。但是我所看到的每一个建议都是设置 EnableEventValidationfalse。我已经搜索了整个代码库,但是没有找到字符串“EnableEventValidation”任何地方。此外,这段代码曾经可以工作;我做了什么明显破坏了页面。但是是什么呢?
当我点击Telerik RadGrid内部的按钮时,会发生错误,声明如下:
<telerik:RadGrid ID="MyGrid" Width="100%" ItemStyle-BorderColor="Gainsboro"
ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px" ActiveItemStyle-BackColor="Bisque"
SelectedItemStyle-BackColor="Black" AllowPaging="True" PageSize="15" runat="server"
AllowSorting="true" OnItemCommand="MyGrid_ItemCommand" AutoGenerateColumns="false"
OnNeedDataSource="MyGrid_NeedDataSource" GridLines="Horizontal" AllowMultiRowSelection="false"
Skin="Black">
  <GroupingSettings CaseSensitive="false" />
  <MasterTableView Width="100%" DataKeyNames="ID" AllowFilteringByColumn="false" Font-Names="Arial"
  Font-Size="10px">
    <Columns>
      <telerik:GridButtonColumn ButtonType="PushButton" Text="Cancel" CommandName="Cancel"
      ConfirmText="Are you sure you want to cancel this?">
      </telerik:GridButtonColumn>
      ...
    </Columns>
  </MasterTableView>
  <PagerStyle Mode="NextPrevAndNumeric" />
  <FilterMenu EnableTheming="True">
    <CollapseAnimation Duration="200" Type="OutQuint" />
  </FilterMenu>
</telerik:RadGrid>

点击“取消”按钮,会出现如下著名错误: 无效的后台或回调参数。事件验证是通过在配置文件中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 来启用的。出于安全考虑,此功能验证后台或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用 ClientScriptManager.RegisterForEventValidation 方法注册后台或回调数据以进行验证。
2个回答

8
这是个问题:在我的Page_Load方法中,我有以下代码:
protected void Page_Load(object sender, EventArgs e) {
  MyGrid.Rebind();
}

在回发时重新绑定网格显然会出现问题。我将其更改为:

protected void Page_Load(object sender, EventArgs e) {
  if (!IsPostBack) {
    MyGrid.Rebind();
  }
}

现在一切都正常工作。


1
我有同样的问题,但是在我的 NeedDataSource 方法或 Page_Load 方法中没有 Grid.Rebind() 或 Grid.Databind()。这种情况发生在我拖动一列进行分组,然后按 ASC/DESC 排序之后。
我只需简单地添加了:
EnableEventValidation="false" 

在我的.aspx页面的<%@ Page %>标记中。排序失败了,但至少我不再收到错误提示。需要注意的是,除了分组列的排序之外,其他所有内容都能正常工作。
这是我在NeedDataSource方法中使用的代码。
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        String connstr = ConfigurationManager.ConnectionStrings["PrimeIntegartionsConnectionString"].ConnectionString;

        SqlDataSource Ds = new SqlDataSource(connstr, BuildSql()); //buildsql simply returns a SQLSelect String "select * from example"
        RadGrid1.DataSource = Ds;
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接