Question

<script type="text/javascript">
    var s = false;
    $(document).ready(function () {
        $("#btnSaveEducation").click(function () {
            s = true;
        });

        window.onload = function () {

            if (s == false) {
                var select = document.getElementById("year");
                for (var i = 2011; i >= 1900; --i) {
                    var option = document.createElement('option');
                    option.text = option.value = i;
                    select.add(option, 0);
                }
            }
        };
    });
</script>

....
...
<body>
 <asp:DropDownList ID="year" runat="server" name="year">
                        </asp:DropDownList>
</body>
....
..

Hello. In Asp.Net Web From, I get this error when I click btnSaveEducation :

[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.]

Why ? Thanks.

Was it helpful?

Solution

Dy default you can't add option in dropdown list from jquery or java-script.

Because Asp.net checks each controls after postback.

You can change the page directive as follow

<%@ Page ... EnableEventValidation="false" %>

which will cause no validation on the server side which is not good thing.

If you want to achieve the above you can use html drop down and use a hidden field and get the selected value from hidden field rather than drop down it will work.

Similar question on SO

  1. asp.net: Invalid postback or callback argument

OTHER TIPS

Just put this code on your aspx file:

if you already have something like <%@ Page ... EnableEventValidation="false" %>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top