asp.net:无效的回发或回调参数

IT技术 c# javascript asp.net html
2021-01-23 11:15:52

我收到此错误:

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

这是什么意思?

这是我的代码:

<%@ 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>

我究竟做错了什么?

我按下提交按钮后收到此错误。

6个回答

在你的 aspx 文件中,你应该把第一行写成这样:

<%@ Page EnableEventValidation="false" %>

如果您已经有了类似的东西 <%@ Page ,只需添加其余的 =>EnableEventValidation="false" %>

我建议不要这样做。

禁用事件验证(坏主意,因为您会以很少的成本失去一些安全性)。
2021-03-17 11:15:52
@user1334007 因为这是他问题的答案。Ms 确实提供了这个来防止这个错误。这并不意味着我同意。他们还添加了 sqldataadapter 。我会同意使用它吗?
2021-03-18 11:15:52
你为什么要发布你不推荐做的事情?
2021-03-20 11:15:52
这是一个非常糟糕的主意
2021-04-03 11:15:52
这个答案是倒退的,我相信 EnableEventValidation="false" 就是你的意思。
2021-04-11 11:15:52

如果您查看第一行文本,您可以了解您的错误是什么。

此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件

您正在动态编辑 lstProblems 下拉列表,因此当您回发 ASP.NET 时会显示“警告!下拉列表中的无效条目!” 并吓坏了抛出那个错误。您必须确定关闭事件验证是否是一个好的解决方案,但我会在做之前研究它,因为它背后的想法是让您的网站免费更安全。

这是另一个 stackoverflow 答案,它比我更好地解释了该做什么: 回发或回调参数无效。使用 '<pages enableEventValidation="true"/>' 启用事件验证

我如何关闭验证?我不是在编辑条目,我只是从数据源添加一次,就是这样
2021-03-28 11:15:52
用户通过 javascript 添加值: $('#lstProblems').html(tmp); 浏览器也有多种方法可以操作 DOM,例如 IE 开发者工具、Chrome 中的检查元素、Mozilla 中的 Firebug 等...
2021-04-01 11:15:52
问题是您正在添加值客户端。ASP 知道它使用一组特定的有效值将下拉列表呈现给页面。客户端选择的值不包含在原始值集中,因此它假设用户修改了下拉列表以添加该值并停止处理页面。
2021-04-05 11:15:52
但用户无法向其中添加值。为什么asp认为他增加了value?
2021-04-07 11:15:52

如果您的 Page_Load() 事件中有代码。尝试添加这个:

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

另一件需要注意的事情是,如果您有嵌套的

<form

.Net 形式中的标记。

这对我有用。谢谢你。在我的母版页中有一个,在子页面中有一个。
2021-03-16 11:15:52
你是对的,那么如何预防呢?因为有时我们无法删除某些 CSS 样式的 <form> 标签
2021-03-17 11:15:52
你让我度过了一天……我给你 2 美分。
2021-03-19 11:15:52
最佳答案,实话实说。
2021-03-24 11:15:52

我在动态绑定的数据列表中遇到了同样的问题,添加 EnableViewState="false" 消除了错误消息。我想如果我以编程方式绑定,那么控件将在每次回帖时填充,视图状态不会“如果每次回调时它可能会或可能不会改变,就必须维护它,这就是我动态绑定它的原因,哈哈。