简体   繁体   English

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

[英]Invalid postback or callback argument - button in Telerik grid

Very famous error message (see below), judging by the number of Google results. 非常着名的错误消息(见下文),根据Google搜索结果的数量来判断。 But every one of them I've seen suggests to set EnableEventValidation to false . 但是我见过的每一个都建议将EnableEventValidation设置为false I have searched my entire codebase, and I cannot find the string "EnableEventValidation" anywhere . 我搜索了我的整个代码库,我无法在任何地方找到字符串“EnableEventValidation”。 Moreover, this code used to work; 而且,这段代码用来工作; something I have done has obviously broken the pages. 我所做的事情显然打破了网页。 But what? 但是什么?

The error happens when I click on a button inside a Telerik RadGrid, declared as: 单击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>

click on the "Cancel" button, and here's the famous 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.

Here's the problem: in my Page_Load method I had: 这是问题所在:在我的Page_Load方法中,我有:

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

The rebinding of the grid on postback was obviously screwing something up. 在回发上重新绑定网格显然是搞砸了。 I changed it to: 我改成了:

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

and everything is working now. 现在一切正常。

I had the same problem but I had no Grid.Rebind() or Grid.Databind() in my NeedDataSource method or Page_Load method. 我有同样的问题,但我的NeedDataSource方法或Page_Load方法中没有Grid.Rebind()或Grid.Databind()。 This happened just after I drag a column to be grouped and then order the grouped column ASC/DESC 这是在我拖动要分组的列然后对分组列ASC / DESC进行排序之后发生的

I simply added 我只是补充道

EnableEventValidation="false" 

in the <%@ Page %> tag of my .aspx page. 在我的.aspx页面的<%@ Page%>标记中。 The ordering fails but at least I no longer get the error. 排序失败但至少我不再收到错误。 As a note everything else works perfectly except the ordering of a grouped column 作为注释,除了分组列的排序之外,其他所有内容都可以正常工作

here is the code I use in the NeedDataSource method 这是我在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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM