Asked by:
Why is this error happening? help appreciated.

Question
-
User186656733 posted
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..
Wednesday, February 19, 2014 1:13 AM
All replies
-
User1992938117 posted
First of all if you have any code on Page Load the do as below:
if (!Page.IsPostBack) { //do something }
Also can avoid the error by adding below line on page directive.
EnableEventValidation="false"
Wednesday, February 19, 2014 1:27 AM -
User186656733 posted
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.
Wednesday, February 19, 2014 11:39 AM -
User697462465 posted
Hi Saavik,
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
if (!IsPostBack) { //Bind your GridView here... }
Hope it helps.
Best Regards,
Terry GuoThursday, February 20, 2014 1:11 AM -
User186656733 posted
Terry,
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.
Thursday, February 20, 2014 12:10 PM -
User724169276 posted
could you post your code here ...
Thursday, February 20, 2014 12:24 PM