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

时间:2011-11-20 21:08:28

标签: asp.net telerik

非常着名的错误消息(见下文),根据Google搜索结果的数量来判断。但我见过的每个人都建议将EnableEventValidation设置为false。我搜索了整个代码库,但找不到字符串“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>

点击“取消”按钮,这是着名的错误:

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.

2 个答案:

答案 0 :(得分:7)

问题出在这里:我用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 :(得分:1)

我有同样的问题,但我的NeedDataSource方法或Page_Load方法中没有Grid.Rebind()或Grid.Databind()。这是在我拖动要分组的列然后对分组列ASC / DESC

进行排序之后发生的

我只是添加了

EnableEventValidation="false" 
&lt;%@ Page%&gt;中的

我的.aspx页面的标签。排序失败但至少我不再收到错误。作为注释,除了分组列的排序

之外,其他一切都能正常工作

这是我在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;
    }