23

I've used the following in web.config

<pages enableEventValidation="false">

This corrects a problem we've been having with Ajax.

We have a web page that if you browse to directly using a standard HTML hyperlink works fine.

If you browse to the page from another page via link inside a gridview and response.redirecting in the RowCommand event to the page passing an ID in the querystring. The page throws errors from controls inside the panel stating

"Invalid postback or callback argument. Event validation is enabled using 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. "

I'm happy to leave the page validation as false as it seems to have had no other effect.

Any ideas what's happening?

Robert
  • 1,835
  • 4
  • 25
  • 30
  • I found [this response](http://stackoverflow.com/a/9104931/1178314) on a dupe question to be quite good and missing here. – Frédéric Oct 15 '15 at 10:03

3 Answers3

14

Read the documentation.

EDIT: For security reasons, it's probably best to leave it set to true wherever you can.

I would therefore recommend that you set it to false only on the individual AJAX pages where it causes problems, while leaving it true in web.config.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    I did read it of course but I found the limited explanation only lead me to believe I would have no problems setting this to false unless someone intentionally tried to be malicious, it doesn't suggest that the rest of the pages will now behave differently. From that I assume it is safe for me to leave it as false. The app in on the intranet and I don't fear malicious attacks. – Robert Oct 01 '09 at 12:29
  • After a little more research I'm going with the suggested EDIT. It makes sense for the app and it is now singing sweetly again, all ajaxed up. – Robert Oct 01 '09 at 14:33
7

From here

Invalid PostBack or CallBack argument error is basically raise because of Event Validation feature. The EventValidation feature is a new feature in ASP.NET 2.0, and provides an additional level of checks to verify that a postback from a control on the client is really from that control and not from someone malicious using something like a cross-site script injection to try and manipulate things. It is part of our overall strategy of increasingly adding security in depth levels to the programming model -- so that developers can be secure by default even if they forget to add security checks of their own.

Now, Invalid PostBack or CallBack argument error may occur when you are firing click event and the object is rebinding or its properties are changed in Page_Load event or someone is trying to hack into your system with cross site scripting. Each time .Net Framework render a page then it associate a unique Guid for all the controls. When binding a gridview or repeater, on each databind framework will associate a new guid for the contorl. So every time when you are firing event make sure Page_Load event does not change the control, because if the control changed the it will have a different Guid which have acutally fired the event for postback. Here are some scenario with this error.

1) 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)

   {

          //Your code for Bind data 

   }

This code will definitely give you solution if this not work then check whether any other control is not giving error.

rahul
  • 184,426
  • 49
  • 232
  • 263
  • Thanks for the input i did have a read on this but the effort to results ratio was not a good one ;) Thanks – Robert Oct 01 '09 at 14:34
4

There is one thing worth adding here: If you want to disable the event validation for a specific control, rather than the entire page, there is a workaround documented here and here (and now referenced in the relevant Connect suggestion):

Simply subclass the relevant WebControl class, and don't set the SupportsEventValidation attribute on the subclass. The subclass will be exempt from event validation.

Tao
  • 13,457
  • 7
  • 65
  • 76