Invalid postback or callback argument

by Raju Maharjan 4. August 2011 15:30

Server Error in '/' Application.

--------------------------------------------------------------------------------

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.

In the context of the data controls, this happens when a control that isn't registered for event validation causes a postback, but surely that can't be the case.. right?


The reason this happens is because we rebind the data control in Page_Load every time which means that we will lose all of the posted data and viewstate. As a result, the ID of the Control is different and when the event is validated there will be no matching unique id and hence event validation will fail. We are acutally raising an event for a button that is no longer in the control tree.

You can work around this by wrapping that code in if (!IsPostBack). This is a good proof of why you should use DataSource controls.

Tags:

ASP.NET

Comments

Add comment


() (Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Sapnep IT Solution

We Provide IT solutions and services to deliver a unique blend of real-business experience with a strong engineering, international project delivery. We are a software development  firm.