0

I am using JavaScript/jQuery to dynamically adding elements to a dropdown list on an WebForms page. This is working fine, but when I post the page back to the server, I get the following error:

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 think I understand what is happening here: ASP.NET is verifying that the list is the same one that was originally served and detects that it has changed. This is a security feature because this indicates data is being submitted from a modified page.

However, in this case, the behavior is valid. And I would prefer not to disable this feature because it is a good security feature for the rest of my page.

Is there any way to tell ASP.NET to ignore only changes to this one list?

EDIT:

My code is in a Web User Control so I thought it might be acceptable to set the EnableEventValidation property for the control. Unfortunately, it appears this property is only available for the entire page.

11
  • How are you posting back? Commented Oct 14, 2013 at 21:42
  • Just by clicking a server button control. Commented Oct 14, 2013 at 21:44
  • Please post the code. Commented Oct 14, 2013 at 21:45
  • What code? It's a button. Clicking it posts back automatically. It's not my code that causes this error, it's ASP.NET. Commented Oct 14, 2013 at 21:46
  • 1
    Usually this happens when you do a custom call to a __doPostBack('ControlID', 'someArguments') any chance you're doing something like this somewhere? Commented Oct 14, 2013 at 21:51

1 Answer 1

1

I found I was able to eliminate this error by creating a custom DropDownList control like this:

public class DropDownListNoEventValidation : DropDownList
{
}

This apparently creates a control called DropDownListNoEventValidation without the attribute SupportsEventValidation.

The result is elimination of the error I was getting before. Unfortunately, it appears ASP.NET does not recognize the selected value if it is an item that was dynamically added to the list. I'm still working on that problem.

UPDATE:

I ended up using a <select> element without runat="server". This was a bit more work, but seemed the most straight forward way to get this to work as expected.

Sign up to request clarification or add additional context in comments.

3 Comments

Sounds interesting. Have you tried using <select runat="server"> to make server-side access to it more easily?
I didn't try that. I guess I could. I don't really know off the top of my head how much server-side functionality there is with this tag.
Well if it ain't broke - don't fix it :) if your solution worked for your - go with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.