[c#] asp.net: Invalid postback or callback argument

I am getting this error:

Server Error in '/' Application.

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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: 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.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentException: 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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8627417
   System.Web.UI.WebControls.ListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +360
   System.Web.UI.WebControls.ListBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618

What does it mean?

Here is my code:

<%@ Page EnableEventValidation="true" Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="EnterData.DataEntry.WebForm1" %>    

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript"></script>

    <link href="../niceforms/niceforms-default.css" rel="stylesheet" type="text/css" />
    <script src="../niceforms/niceforms.js" type="text/javascript"></script>

    <link href="../jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .list-problems {
        height:600px !important;
        width:200px !important;
        display:inline-block;
    }
    </style>

    <script>
        jQuery(function($) {
        //$("#occurrence_dateTextBox").mask("99/99/9999");
        //$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
        $("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
        $("#<%= report_dateTextBox.ClientID %>").datepicker();
        //$(".datepicker").datepicker(); 

    });
    $(function() {
        $.get('../file.txt', function(data) {
            var output = data.split('\n'),
            tmp = '';
            for (i = 0; i < output.length; i++) {
                tmp += '<option value=' + output[i] + '>' + output[i] + '</option>';
            }
            $('#lstProblems').html(tmp);

        });
    });

    $(function() {
        $("select").multiselect();
    });

    function getselectedproblems() {
        var selectedLanguages = new Array();
        jQuery('#lstProblems option:selected').each(function() {
            selectedLanguages.push(jQuery(this).val());
        });
    }

    </script>

</head>
<body><div id="container">
    <form id="form1" runat="server" class="niceform">

        <fieldset>

        <legend>Section A</legend>

        <dl>

            <dt><label for="occurrence_dateTextBox" >Occurrence Date:</label></dt>
            <dd><asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="report_dateTextBox">Report Date:</label></dt>
            <dd><asp:TextBox ID="report_dateTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="spec_idTextBox">Specimen ID:</label></dt>
            <dd><asp:TextBox ID="spec_idTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="batch_idTextBox">Batch ID:</label></dt>
            <dd><asp:TextBox ID="batch_idTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="report_byTextBox">Report By:</label></dt>
            <dd><asp:TextBox ID="report_byTextBox" runat="server" size="50"/></dd>
        </dl>

        <dl>

            <dt><label for="identified_byTextBox">Identified ID:</label></dt>
            <dd><asp:TextBox ID="identified_byTextBox" runat="server" size="50"/></dd>
        </dl>

        </fieldset>

        <fieldset>
        <legend>Section B</legend>

        <dl>

            <dt><label for="problemTextBox">Problem:</label></dt>
            <dd><asp:TextBox ID="problemTextBox" runat="server" size="50"/></dd>


        </dl>

        <dl>
            <dt><label for="lstProblems">Problems List:</label></dt>
            <dd>
                <asp:ListBox ID="lstProblems" runat="server" SelectionMode="Multiple" CssClass="list-problems"></asp:ListBox>
            </dd>

        </dl>  

        <dl>
                <dd><select size="8" multiple="true" >
                <optgroup label="Europe">
                    <option>United Kingdom</option>
                    <option>Luxembourg</option>
                </optgroup>    
                <optgroup label="Asia">
                    <option>India</option>
                    <option>Dubai</option>
                </optgroup>
            </select> </dd>    
        </dl>
        <dl>
            <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" 
                DataTextField="batch" DataValueField="batch" SelectionMode="Multiple" 
                Height="100px" Width="329px"></asp:ListBox>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:LOM %>" 
                SelectCommand="SELECT [batch] FROM [lom_batch]"></asp:SqlDataSource>
        </dl>

        </fieldset>

        <fieldset>
        <legend>Section C</legend>
        <dl>

            <dt><label for="section_c_issue_error_identified_byTextBox">Issue/Error Identified By:</label></dt>
            <dd><asp:TextBox ID="section_c_issue_error_identified_byTextBox" runat="server" size="50"/></dd>


        </dl>

        <dl>

            <dt><label for="section_c_commentsTextBox">Comments:</label></dt>
            <dd><asp:TextBox ID="section_c_commentsTextBox" runat="server" size="50"/></dd>


        </dl>       

        </fieldset>

        <fieldset>
        <legend>Section D</legend>
        <dl>

            <dt><label for="section_d_investigationTextBox">Investigation:</label></dt>
            <dd><asp:TextBox ID="section_d_investigationTextBox" runat="server" size="50"/></dd>


        </dl>

        </fieldset>

        <fieldset>
        <legend>Section E</legend>
        <dl>

            <dt><label for="section_e_corrective_actionTextBox">Corrective Action:</label></dt>
            <dd><asp:TextBox ID="section_e_corrective_actionTextBox" runat="server" height="200" TextMode="MultiLine" size="50"/></dd>


        </dl>


        </fieldset>

        <fieldset>
        <legend>Section F</legend>
        <dl>

            <dt><label for="section_f_commentsTextBox">Comments:</label></dt>
            <dd><asp:TextBox ID="section_f_commentsTextBox" runat="server" size="50"/></dd>


        </dl>

        </fieldset>

        <fieldset>
        <legend>Pre-Analytical</legend>
        <dl>

            <dt><label for="prePracticeCodeTextBox">Practice Code:</label></dt>
            <dd><asp:TextBox ID="prePracticeCodeTextBox" runat="server" Visible="false"/></dd>


        </dl>

        <dl>

            <dt><label for="preContactTextBox1">Contact:</label></dt>

            <dd><asp:TextBox ID="preContactTextBox" runat="server" Visible="false"/></dd>


        </dl>

        <dl>
            <dt><label for="CheckBox1">PreAnalytical?</label></dt>
            <dd> <asp:CheckBox ID="CheckBox1" runat="server" CausesValidation="false"
                            Visible="true" AutoPostBack="true" OnCheckChanged="CheckBox1_CheckedChanged"/></dd>
        </dl>

        </fieldset>

        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="SubmitData"  OnClientClick="JSfunction()"/>

    </form>

</div></body>
</html>

What am I doing wrong?

I am getting this error after I press the submit button.

This question is related to c# javascript asp.net html

The answer is


I had the same problem, two list boxes and two buttons.

The data in the list boxes was being loaded from a database and you could move items between boxes by clicking the buttons.

I was getting an invalid postback.

turns out that it was the data had carriage return line feeds in it which you cannot see when displayed in the list box.

worked fine in every browser except IE 10 and IE 11.

Remove the carriage return line feeds and all works fine.


You can add ViewStateMode="Disabled"

asp:UpdatePanel ID="UpdatePanel1" runat="server" ViewStateMode="Disabled"


You can also fill you data in the prerender event. This way you can keep your validation and stay secure. Here is an example using a repeater.

protected void Page_PreRender(object sender, EventArgs e)
     {
        List<Objects.User> users = Application.User.GetAllUsers();

        Repeater1.DataSource = users;
        Repeater1.DataBind();
      }

Ah its unfortunate. Since you add them essentially client side asp.net blows up. It is also unfortunate you'd have to turn off EventValidation as there are some important protections that helps (for instance evil injection into drop down boxes). The other alternative is to make your own composite control, which of course here seems a bit more than the effort involved. I'd prob turn off event validation too but be very careful that you don't trust any values from the page that could be used in a bad manner by simply changing them - like hidden keys, sql injection through combo boxes, etc.


if you change UseSubmitBehavior="True" to UseSubmitBehavior="False" your problem will be solved.

<asp:Button ID="BtnDis" runat="server" CommandName="BtnDis" CommandArgument='<%#Eval("Id")%>' Text="Discription" CausesValidation="True" UseSubmitBehavior="False" />

I had a similar problem because of copy paste from another page, what I got:

<form id="form1" runat="server">
    ...
    <form id="form2" runat="server">
    ....
    </form>
</form>

I just removed form with id="form2" inside form with id="form1" and issue gone. This could be not your problem but it could be something similar.


This is probably not the cause of your issue, but I noticed you were using optgroups in your dropdown so I figured this might help someone should they wind up here with this issue. For me, I needed to create a dropdownlist that would render with optgroups, and I ended up using the accepted answer here but while it would render the control correctly, it gave me this error. How I got past that is detailed in my answer here.


My problem was that i had nested form tags. After removing the inner one, worked out for me.


This error can also be caused by nested <form> tag in the master page which is not allowed.

<form id="someid"></form>

This will likely be the cause if you have picked up a template and copying the code from somewhere as it.

Solution

You have to break the nesting of <form> tag. The following should become

<form method="" name="form1">
  <form method="" name="form2>
  </form>
</form>

should become

<form method="" name="form1">    
</form>

<form method="" name="form2>    
</form>

After having this problem on remote servers (production, test, qa, staging, etc), but not on local development workstations, I found that the Application Pool was configured with a RequestLimit other than 0.

This caused the app pool to give up and reply with the exception noted in the question.

Somewhere along the way my installshield project had its App pool definition changed to use "3" (probably just a mis-click or mis-type).


I had this same problem with a datalist I"m dynamically binding, adding EnableViewState="false" quieted the error message. I figure if I'm binding programmatically, then the control is being populated on each post back, the view state doesn't have to be maintained if it may or may not change on each call back, that's why I'm dynamically binding it, lol.


If you have code in your Page_Load() event. Try adding this:

if (!Page.IsPostBack)
{ 
//your code here 
}

My solution was to add:

ctlUpdatePanel.Update();

after binding control after postback. it was in updatepanel with UpdateMode="Conditional" attribute.


If you look at the first lines of text you can glean what your error is.

this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them

You're dynamically editing the lstProblems dropdown, so when you post back ASP.NET says "Warning! Invalid entries in the dropdown!" and freaks out throwing that error. You have to determine if turning off event validation is an OK solution, but I would research it before doing it, since the idea behind it is to make your site more secure for free.

Here's another stackoverflow answer that does a much better job explaining what to do than me: Invalid postback or callback argument. Event validation is enabled using '<pages enableEventValidation="true"/>'


Add on top page

protected void Page_Load(object sender, EventArgs e)
{    
    if (!Page.IsPostBack)
    {
        //Code display data
    }
}

Another thing to watch out for, is that this error can happen if you have a nested

<form

tag within the .Net form.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment