invalid postback or callback argument

Posted by GoLive under Regular Expressions on 10/5/2010 | Points: 10 | Views : 2308 | Status : [Member] | Replies : 4
Hi,

I am having a big problem solving this 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."

Scenario:

I have a gridView which will be loaded with data when the page loads for the first time. In the same page i have one search user control outside of GridView which have dropdown and a submit button. User select from dropdown and click submit button to pass dropdown selected index. The page reloads and bind the Grid again with new information related with search.
My GridView also have one user control inside gridview ItemTemplate which have labels, textboxex, checkboxes created dynamically. Such that when each row of GridView is clicked, it opens up with data related to that row and dynamically binds controls with information.
Now, When i do search GridView filters out the information and show data correctly, which is fine till here, but once i click on each row to see its inner part it display the above error.
When no search is performed, everything works fine.
I am guessing when Search is performed, the grid is rebind again to new datasource on page load and hence changes all controls IDs. Since postback is performed and server is not getting correct control indentification, the server is throwing that error.

Any help would be apprciated alot.

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
DataTable mDT = Utility.BuildDataTable("SELECT * FROM TABLE");
GridView1.DataSource = mDT;
GridView1.DataBind();
}


// Search results

int ddltypeID = ddl.SelectedValue;
String strSql = "";
String strAnd = "";


if (ddltypeID != -1)
{
strSql = strSql + strAnd + "Measure_Type = " + UCTypeID;

DataTable dt = msadapter.GetData();
DataRow[] dr = dt.Select(strSql);

GridView1.DataSource = dr;
GridView1.DataBind();

}

}




Responses

Posted by: SheoNarayan on: 10/6/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi GoLive,

As you mentioned tis something to do with the Control ids. Did you do whatever is suggested in the error? If that doesn't solve the problem look at this post http://weblogs.asp.net/gunnarpeipman/archive/2009/05/10/invalid-postback-or-callback-argument-event-validation-is-enabled-using-in-configuration.aspx.

Or alternatively you may set following to your web.config file

<pages validateRequest="false" enableEventValidation="false" />


Hope these stuffs will give some clue and help you solving your problem.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

GoLive, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prasham on: 10/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hello,

This is because of the ASP.NET event validation. Please try by setting EnableEventValidation to false in page directive. Or you can also set this property to false in web.config file.

Please visit this link once - http://channel9.msdn.com/forums/TechOff/155642-Invalid-postback-or-callback-argument-Wants-event-validation-enabled/

Thanks and Best Regards
Prasham

GoLive, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/6/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Looking at your problem you have mentioned

checkboxes created dynamically.

I had the same problem , but i was adding the items on the listbox dynamically. Disabling the event validation here will not help you, because it will still happen even though not all the time. What you will need here to sctructure your controls correctly and manage your partial postbacks correctly

Thank you for posting at Dotnetfunda
[Administrator]

GoLive, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GoLive on: 10/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Vuyiswamb,

Thank you for your reply. Do you have any example that i can look around.

I am really stuck in this project and not able to go ahead.

GoLive, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response