0

Im getting the following error when I click on any item in my ListBox:

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.

However, I've set AutoPostBack="True" in my ListBox and also in my DropDownList:

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

and I've set if (!Page.IsPostBack) in my .cs code:

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);
        }

    }
}

Anyone know how to get rid of the error?

kac26
  • 381
  • 1
  • 7
  • 25

1 Answers1

0

The error it self says you need to add "<%@ Page EnableEventValidation="true" %> " in page, like below :-

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

and the error gets sorted out.