2011-11-20 68 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; 
    } 
相關問題