I developed a custom web part that basically renders a form and submits the entered data into a SharePoint list. The problem I was having is that when the form button was clicked, I got the following 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.”

This error message is related to a new security enhancement brought by ASP.NET 2.0 called EventValidation. If enabled (default value), this new feature ensures that ASP.NET will only allow the specific events that are raised on a given control during a postback or callback. The main purpose of this security validation is to reduce the risk of unauthorized postback requests and callbacks (more information on this here).

After some research on the Internet, two main approaches were given:

  • Set the <pages EnableEventValidation=”false” …/> in the web.config or at the page level – This is not a recommended approach due to the associated security risks, since event validation will not be performed and the risk of unauthorized postback requests and callbacks will increase.
  • Use the Page.ClientScript.RegisterForEventValidation(ctrl. UniqueID) in the control – this approach will register the given control and its events for event validation. This seemed like a good approach since it would allow maintaining the event validation but it didn’t solve the problem. Apparently, the internal variable _requestValueCollection of the Page class, is never initialized, so method EnsureEventValidationFieldLoaded will never load the dictionary with UniqueIDs and therefore cannot find the control which is authorized to make postback via RegisterForEventValidation.

After this, I tried a different approach, more successfully. The web part is included in the context of a SharePoint page layout. After analyzing this web page, I found out that it included two nested <form></form> elements. After removing these elements, the form submission started working properly.

Related Articles

To learn why your business should migrate to SharePoint Online and Office 365, click here and here.

If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these learning resources.

If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read this article.

If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click here.

If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint 2019 farm in an automated way using PowerShell, I invite you to click here and here.

If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click here and here.

If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click here.

If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click here.

If SharePoint 2019 is still not an option, you can learn more about how to install a SharePoint 2016 farm in an automated way using PowerShell, click here and here.

If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click here and here.

If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click here and here.

Happy SharePointing!

LEAVE A REPLY

Please enter your comment!
Please enter your name here