[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

how to fix an ASP.NET 2.0 error?

Hi, I am getting the following error:

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.

Please, can some one help?
  • 3
1 Solution
vielkacarolina1239Author Commented:

I understand why I am getting this error. The reason is that I have a web user control that contains 4 dropdown menus. I loop through all 4 drop down menus and set some data into the drop down menus controls in the ascx.cs file.

                DropDownList[] dropDownListArr = new DropDownList[12];
                dropDownListArr[0] = DropDownList0;
                dropDownListArr[1] = DropDownList1;
                dropDownListArr[2] = DropDownList2;
                dropDownListArr[3] = DropDownList3;

                for (int i = 0; i < 4; i++)
                     dropDownListLabelArr[i].Text = "text" + i.ToString();

I know that if I use the following code in the web config, the problem will go away
    <pages enableEventValidation="false" />

However, I don't whant to use the above line of code. Is there another way to solf this problem?
vielkacarolina1239Author Commented:
The looping of the dropdown menus is been done in the Page_Load event of the ascx.cs file
vielkacarolina1239Author Commented:
I also found that I need to implement IPostBackDataHandler interface for the control that is been changed in the Page_Load event. This will register the changes in the dropdown menus and update the ViewState for this control accordantly when I pass the dropdown menu to the following method.

Please, can some one show me how to implement IPostBackDataHandler interface for a drop down menu so that I can use RegisterRequiresPostBackt() and this will update the ViewState when there is a changed in a drop down menu?
When you say dropdown menu, do you just mean a standard dropdownlist control?
If you are adding items programatically in your code behind you shouldn't need to register anything, the items will be automatically added to the viewstate. Are you making any client side changes with javascript?
Also, if it is a dropdownlist you'll want to modify its contents using the items collection, eg. Dropdownlist1.items.add("Text") or Dropdownlist1.items[0].text = "Text" something like that.

Sorry if I've got the wrong end of the stick.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now