“pages enableEventValidation=”true” + possible solutions

Today I had an error (one of many if you are a developer) and it threw me off a bit.

I’m using a visual webpart (VS 2010 with SP 2010) and it has an asp:repeater with buttons. Ok so far so good, now i’m testing the buttons and 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.

Ok, after a lot of searching you can find:

add a <pages enableEventValidation=”true”/> in the ASCX file – wrong

add a <%pages enableEventValidation=”true”/%> (or something with extra symbols) in the ASCX – wrong

add public void Page_preinit(…) { page.enableEventValidation=”false” }       – wrong

replace all trues with false  – wrong

the only thing you need to do is to set EnableViewState=”false” 🙂

happy hunting for the bugs

*! Edit !*

I must first say that above “solution” does fix things but I’ve discovered later in the game that this will not help you when you want to do special things.

I’ve got an updatePanel, inside of it an Asp:Repeater and inside the repeater a FileUpload

than that’s quit a different story all together.

In the end, the way it works for me, I’ve added <triggers> <asp:PostBackTrigger control=”name of the repeater” /> </triggers>

And I’ve put the enableviewstate to true

also because I have multiple controls the ID cannot be the same (ofcourse) so you need to add an event “ItemDatabound” to your repeater (in the code behind)

For each row you need to change the ID of the control

For Example:

var item = (DataRowView)e.Item.DataItem;

var button = (Button)e.Item.FindControl(” ID NAME”);

button.CommandArgument = e.Item.ItemIndex.ToString();

button.ID = ” ID NAME” + e.Item.ItemIndex.ToString();

Every control is unique because I have name of the ID control + Indexnumber .

There are other ways but remember, you maybe also need to retrieve the unique control, so item.itemindex is the most easiest way to go

hope it helps someone

Leave a Reply

Your email address will not be published. Required fields are marked *