Last post Feb 20, 2014 12:24 PM by Ashim Chatterjee
Feb 19, 2014 01:13 AM|Saavik|LINK
I have a page with a GridView with is bound by SqlDataSource.
The page also has 2 Textboxes that can be used to filter the data.
When user enters data into the filter, I change the SqlDataSource.SelectCommand, issue a SqlDataSource.Select() and rebind the GridView (MyGridView.DataBind() ).
All this works as long as the SqlDataSource.Select() returns at least 1 record. If the SqlDataSource.Select() returns 0 records and user tries the filter again (with same or different filter data), this error occurs:
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.
Why is this happening?
I have done a similar filter a thousand times before and have never seen this error.
Help is most appreciated..
Feb 19, 2014 01:27 AM|Rajneesh Verma|LINK
First of all if you have any code on Page Load the do as below:
Also can avoid the error by adding below line on page directive.
Feb 19, 2014 11:39 AM|Saavik|LINK
Thank you for these suggestions.
Your first suggestion seemed very reasonable, but, unfortunately the problem persists.
From everything I have read and seen, EnableEventValidation="false" should not be used.
Help most appreciated.
Feb 20, 2014 01:11 AM|Terry Guo - MSFT|LINK
Invalid Postback or Callback argument in GridView Problem may be: You are binding data in Page_Load event with either Object Data Source or Manual Binding with function call. This will make your GridView bind data on every event fire of any control.
When you are firing any GridView command with OnRowCommand, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event.
Solution for Invalid Postback or Callback argument in GridView: You can bind your data within this if condition
//Bind your GridView here...
Hope it helps.
Feb 20, 2014 12:10 PM|Saavik|LINK
Thank you for this suggestion. I tried it and, unfortunately, the problem persists.
I used !IsPostBack in Page_Load. Obviously it cannot be used everywhere or the user will never be able to change the filter.
Ideas most appreciated.
Feb 20, 2014 12:24 PM|Ashim Chatterjee|LINK
could you post your code here ...