簡體   English   中英

無效的回發或回調參數。 設置了AutoPostBack,還設置了Page_Load中的!Page.IsPostBack

[英]Invalid postback or callback argument. AutoPostBack is set and also !Page.IsPostBack in Page_Load

我在列表框中單擊任何項​​目時收到以下錯誤:

無效的回發或回調參數。 使用配置或頁面中的<%@頁面EnableEventValidation =“ true”%>啟用事件驗證。 為了安全起見,此功能驗證回發或回調事件的參數源自最初呈現它們的服務器控件。 如果數據有效且預期,請使用ClientScriptManager.RegisterForEventValidation方法以注冊回發或回調數據以進行驗證。

但是,我已經在ListBox和DropDownList中設置了AutoPostBack =“ True”:

<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true"  CodeBehind="Form1.aspx.cs" Inherits="WebApplication1.Form1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="dropDown" runat="server" AutoPostBack="True" Height="19px" Width="226px">
            </asp:DropDownList>
        </div>
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" Height="349px" Width="501px" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" ></asp:ListBox>
        <br />
    </form>
</body>
</html>

並且我在.cs代碼中設置了if(!Page.IsPostBack):

using System;
using System.Collections.Generic;
using System.Web.UI;

namespace WebApplication1
{
    public partial class Form1 : System.Web.UI.Page
    {
        public ServiceReference1.WebService1SoapClient client= new ServiceReference1.WebService1SoapClient();
        public localhost.WebService1 asd = new localhost.WebService1();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                 List<string> igralci = new List<string>();
                 foreach (localhost.Igralec ig in asd.vrniVseIgralce())
                 {
                     igralci.Add(ig.id + ", " + ig.ime + ", " + ig.priimek + ", " + ig.letoRojstva + "\n");
                 }
                 ListBox1.DataSource = igralci;
                 ListBox1.DataBind();


                List<string> klubi = new List<string>();
                klubi.Add("Vsi klubi");
                foreach (localhost.Klub ig in asd.vrniVseKlube())
                {
                    klubi.Add(ig.naziv);
                }

                dropDown.DataSource = klubi;
                dropDown.DataBind();

            }
        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string script = "alert(\"Hello!\");";
            ScriptManager.RegisterStartupScript(this, GetType(),
                                  "ServerControlScript", script, true);
        }

    }
}

有人知道如何消除錯誤嗎?

錯誤本身表明您需要在頁面中添加“ <%@頁面EnableEventValidation =“ true”%>“,如下所示:-

“ <%@頁面語言=” C#“ AutoEventWireup =” false“ EnableEventValidation =” false“ CodeBehind =” Form1.aspx.cs“ Inherits =” WebApplication1.Form1“%>”

並且錯誤得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM