0

I am getting this error and trying to find a solution for it:

"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 have been struggling with that error for couple of hours, I looked for solution and find a lot of information about it like that one- but I still don't know how to solve that ( i don't want to Disable eventvalidation )

I am guessing that the error is because I am adding / removing items from drop-down list causing the drop-down values being different from what it loaded with initialy. (so it preventing from clients(like developer tools in chrome) to edit this value)

What can I do in order to solve that? will an ajax call to server after any adding or removing items will do?

This is the code that causing the error

 $(".hdn-FU").change(function(el){

        var labelText = $('.fuCatControl .file-upload-lbl').text();
        var ddl = $('.fuCatControl .thumbnailCombo');
        var hidChosenValue = $('#fuCatControl_oldValue');

        if (labelText != "No file chosen" && labelText != "" && labelText != null) {
            //we need to append the new file name to ddl and delete old one if exist
            if (hidChosenValue.val() != "") {
                ddl.find("option[value='" + hidChosenValue.val() + "']").remove();
            }

            hidChosenValue.val(labelText);
            ddl.append("<option selected='selected' value='" + labelText + "'>" + labelText + "</option>");
        }
    });
E.Meir
  • 2,146
  • 7
  • 34
  • 52
  • "I am guessing that the error is because I am adding / removing items from drop-down list causing the drop-down values being different from what it loaded with initialy" Yes I think that's probably it. You have to run without EventValidation enabled, unfortunately, which is a risk you can decide to take, or not. It's one of many irritations with ASP.NET Forms. In the end I moved to using MVC, which is much more friendly to this kind of thing. – ADyson Jul 27 '17 at 15:41
  • @ADyson yes, but there are still live apps that use "old" technologies like asp.net. what i ended up doing- on click event (client click) i clear the ddl and that solve it. – E.Meir Jul 27 '17 at 17:28
  • Sorry it was only meant to be a passing remark. I only made the switch a year ago. Plenty of my stuff written in Forms still in production, with lots of ajax in it. Sometimes we just had to find little workarounds for stuff like this though, which aren't necessary in MVC. That's all I was saying. All frameworks have upsides and downsides, Forms still does a great job in lots of situations. Glad you were ale to fix it. – ADyson Jul 28 '17 at 07:07
  • If it's useful, from memory in the past I think we used a workaround by having the select as a native HTML element (not as an – ADyson Jul 28 '17 at 07:08
  • @ADyson interesting work around, but i don't think i can use it in my case cause the drop-down is getting filled initially from server – E.Meir Jul 30 '17 at 06:36
  • You can still do it in that case, but you have to build the ` – ADyson Aug 02 '17 at 10:16

0 Answers0