2

I am adding list items in a dropdownlist using javascript and when I click on submit button I get this 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.    

Following is my code

<asp:DropDownList ID="dropdownlist" runat="server"></asp:DropDownList>

<script>
        var arr = "john,bob,david".split(',');
        for (var i = 0; i < arr.length; i++) {
            $('#dropdownlist').append('<option value="'+arr[i]+'">'+arr[i]+'</option>');
        }
</script>

I know this question has already been asked but none of the solution worked for me.

Twix
  • 412
  • 1
  • 6
  • 17
  • 1
    what is `row`? and why you have `ddServeMeasure` but in js use `#dropdownlist`? and where `submit` button? _sidenote_:you not need `arr = new Array()` if immediately thereafter you do `arr = "john,bob,david".split(',');` – Grundy Apr 23 '15 at 08:19
  • 2
    possible duplicate of [Invalid postback or callback argument. Event validation is enabled using ''](http://stackoverflow.com/questions/228969/invalid-postback-or-callback-argument-event-validation-is-enabled-using-page) – Grundy Apr 23 '15 at 08:37
  • _none of the solution worked for me._ what you try, and what you mean _not wokred_? errors or what? – Grundy Apr 23 '15 at 09:32
  • I tried putting the dropdown in update panel and got same error. I cannot set eventvalidation property to false. – Twix Apr 23 '15 at 09:53
  • so why you want add item on client? why not fill dropdown on server? – Grundy Apr 23 '15 at 09:58
  • because I am creating a list (not dropdownlist) using javascript and selecting data from the list. on selection I want to fill the dropdown. – Twix Apr 23 '15 at 10:00
  • are you try this [answer](http://stackoverflow.com/a/3758957/2881286)? – Grundy Apr 23 '15 at 10:02
  • yes. I have tried dat but didn't work – Twix Apr 23 '15 at 10:37
  • @Twix "I tried it but it didn't work" is not a detailed enough response. What do you mean by "didn't work"? Nothing happened? Did it post an error? Did your computer blow up? Did it show a result, but not the one you expected? We need details about your scenario in order assist you. – TylerH Apr 24 '15 at 21:39
  • @TylerH it does nothing but throwing same 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. ` – Twix Apr 27 '15 at 04:50

1 Answers1

0

I could not resolved this issue but I found alternate way.

Instead of using asp dropdownlist I am using html for the same purpose and using Request object to get the value at server side.

Twix
  • 412
  • 1
  • 6
  • 17