2011-11-20 82 views
3

非常着名的错误消息(请参见下文),由Google结果的数量来判断。但他们中的每一个人都建议将EnableEventValidation设置为false。我搜索了我的整个代码库,并且我找不到任何地方的字符串“EnableEventValidation”。而且,这个代码使用工作;我所做的一切显然已经打破了页面。但是什么?无效的回传或回调参数 - Telerik网格中的按钮

当我点击一个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.

回答

6

这里的问题:在我的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

我只是在我的.aspx页面中的<%@页%>标签添加

EnableEventValidation="false" 

。排序失败,但至少我不会再收到错误。作为一个说明一切完美的作品,除了一个分组列

这里的排序是我在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; 
    } 
相关问题