Link to home
Start Free TrialLog in
Avatar of vielkacarolina1239
vielkacarolina1239Flag for United States of America

asked on

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?
Avatar of vielkacarolina1239
vielkacarolina1239
Flag of United States of America image

ASKER


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?
The looping of the dropdown menus is been done in the Page_Load event of the ascx.cs file
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.
RegisterRequiresPostBack(myDropDownMeny)

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?
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial